Jump to content

Adding error messages for registration form


Recommended Posts

I have added new fields into the registration form on my site, but now i don't undestand how can i add new control for the new field.

 

For example i have added one new required field so i need to add an error like the other required field (name, surname, email...)

I also need an error message for the field "confirm password", when it's different from the password.

 

Someone could help me?

 

 

 

PS: I'm using prestashop 1.4.9

Link to comment
Share on other sites

I have added new fields into the registration form on my site, but now i don't undestand how can i add new control for the new field.

 

For example i have added one new required field so i need to add an error like the other required field (name, surname, email...)

I also need an error message for the field "confirm password", when it's different from the password.

 

Someone could help me?

 

 

 

PS: I'm using prestashop 1.4.9

 

Try editing the AuthController.php file under "controllers" folder.

 

find the line of code below

 

if (Tools::isSubmit('submitAccount') OR Tools::isSubmit('submitGuestAccount'))
{

 

Add this line of code inside it together with the code to be executed...

 

 

if (!Tools::getValue('
yourinputname
') {$this->errors[] = Tools::displayError('Yourinputname Input required');}

 

Change yourinputname to your input field's name.

 

To be safe, use prestashop's override feature to make the changes.

Edited by yewster (see edit history)
Link to comment
Share on other sites

I actually missed a ")" in my previous code.

 

 

<input type="checkbox" name="privacy" id="privacy" value="1" />

 

 

For checkbox you need to do it differently.

 

Try this for your checkbox

 

if (Tools::getValue('privacy
') != "1") {$this->errors[] = Tools::displayError('You need to check the privacy checkbox');}

 

Insert it under

 

if
(
Tools
::
isSubmit
(
'submitAccount'
)
OR
Tools
::
isSubmit
(
'submitGuestAccount'
))

 

In AuthController.php file under "controllers" folder.

Link to comment
Share on other sites

Thanks it works, but i have removed the {}:

if (Tools::getValue('privacy') != "1")
$this->errors[] = Tools::displayError('You need to check the privacy checkbox');

 

Could you also help me to add a message for the confirm password, when it isn't the same as the password?

<input type="password" class="text" name="passwd_confirm" id="passwd_confirm" />

must be = to:

<input type="password" class="text" name="passwd" id="passwd" />

Link to comment
Share on other sites

I solved by adding this code before the privacy check:

  if ((Tools::getValue('passwd')) != (tools::getValue('passwd_confirm')))
$this->errors[] = Tools::displayError('Error message');

 

But now i have another problem, i see that if i leave empty the fields firstname and lastname in the error message list i see "firstname required" and "lastname required" 2 times, how can i fix it?

Edited by DARKF3D3 (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...