duplicate address error

  • Posts: 27
  • Thank you received: 0
12 years 11 months ago #40433

Hi,
I want to make sure the phone number each person writes is unique.
I have set the database cell to be unique, but I wan't to display error massage for the user.
can some one please tell me on how to do that? Nicolas, are you here? :)

Thanks for your help

Please Log in or Create an account to join the conversation.

  • Posts: 27
  • Thank you received: 0
12 years 11 months ago #40441

ok, I did a little digging, and found out this:
in the file: /components/com_hikashop/controllers/address.php
on line 72 it's saves the address using this code:

$address_id = $addressClass->save($addressData);
so, I added my code:
if (!$address_id) {
				echo 'phone already assigned to user, please select a different one';
			}
so now I can see (for a sec) this error massage when trying to insert a duplicate phone number in address, and then it returns to the form.
the thing is, I want to check that this is the error (
if (mysql_errno() == 1062) {
    print 'phone already assigned to user, please select a different one';
}
and then return this text to the form.
any idea on how to do it?

Last edit: 12 years 11 months ago by justaguy.

Please Log in or Create an account to join the conversation.

  • Posts: 83103
  • Thank you received: 13416
  • MODERATOR
12 years 10 months ago #40615

You should do like that:

if (!$address_id) {
$app=&JFactory::getApplication();
$app->enqueueMessage('phone already assigned to user, please select a different one');
}

Please Log in or Create an account to join the conversation.

  • Posts: 27
  • Thank you received: 0
12 years 10 months ago #40652

Thanks for your reply.
but does this error checks to see if the error is duplicate phone or is it just to show an error if form could not submit it to database.
I have added another custom field which is password (would love to see password field in the custom fields options) and I wan't to check it for only digits and present and error for the user.
as I see in your solution that you made, the error massage is the same for all the errors when a user tries to save his address.
I wan't to check for the error number so I can present the right error massage to my users.

Thank you for your help.

Please Log in or Create an account to join the conversation.

  • Posts: 83103
  • Thank you received: 13416
  • MODERATOR
12 years 10 months ago #40872

For the password, you should check it via javascript if you want by adding an onchange event directly to the input field.

Otherwise, if you want a fine grained check of your addresses, one solution could be to create a hikashop plugin implementing the address API:
www.hikashop.com/en/support/documentatio...ntation.html#address
That way, you will be able to add any checks you need on addresses even before they are saved to the database.

Please Log in or Create an account to join the conversation.

Time to create page: 0.065 seconds
Powered by Kunena Forum