Jump to content
Nesta78

How to add Password confirm Field in 1.7 ?

Recommended Posts

Hello,

I'd like to add a password confirm field on registration page.

I use PS 1.7.

Could you please help me guys ?

Thank you :-)

Share this post


Link to post
Share on other sites
On 03/07/2018 at 9:38 AM, ENS Enterprises said:

ok, let me do that and share the code.

Are you serious ? It would be so cool :-)

Share this post


Link to post
Share on other sites

Please, if anyone have a solution  using PS 1.7.5.0.   , could you help me?

Share this post


Link to post
Share on other sites

Hello,

I'm using PS 1.7.5.1 and I made a customization to insert email and password confirmation:

BACKUP FIRST!!

 

Download those 2 files

/classes/form/CustomerFormatter.php

/classes/form/CustomerForm.php

open the file CustomerFormatter.php and search

$format['email'] = (new FormField())

paste above

	$format['email'] = (new FormField())
            ->setName('email')
            ->setType('email')
            ->setLabel(
                $this->translator->trans(
                    'Email', [], 'Shop.Forms.Labels'
                )
            )
            ->setRequired(true)
        ;

this code:

		$format['conf_email'] = (new FormField)
			->setName('conf_email')
			->setLabel(
				$this->translator->trans(
					'Confirm e-mail', [], 'Shop.Forms.Labels'
				)
			)
			->setRequired(true)
		;

Then after:

        if ($this->ask_for_new_password) {
            $format['new_password'] = (new FormField())
                ->setName('new_password')
                ->setType('password')
                ->setLabel(
                    $this->translator->trans(
                        'New password', [], 'Shop.Forms.Labels'
                    )
                )
            ;
        }

paste this code:

		$format['conf_password'] = (new FormField)
			->setName('conf_password')
			->setType('password')
			->setLabel(
				$this->translator->trans(
					'Confirm password', [], 'Shop.Forms.Labels'
				)
			)
			->setRequired(true)
		;

 

Now open CustomerForm.php and search 

public function validate()

after this code:

	$emailField = $this->getField('email');
        $id_customer = Customer::customerExists($emailField->getValue(), true, true);
        $customer = $this->getCustomer();
        if ($id_customer && $id_customer != $customer->id) {
            $emailField->addError($this->translator->trans(
                'The email is already used, please choose another one or sign in', array(), 'Shop.Notifications.Error'
            ));
        }

Paste the following code:

//Confirm Email - check if is the same
		$confEmailField = $this->getField('conf_email');
		$emailValue = $emailField->getValue();
		$confEmailValue = $confEmailField->getValue();
		if ($emailValue != $confEmailValue) {
            $confEmailField->addError($this->translator->trans(
                "The email and the confirmation email don't match", array(), 'Shop.Notifications.Error'
            ));
        }
		

		//Confirm password - check if is the same
		$passwField = $this->getField('password');
		$confPasswField = $this->getField('conf_password');
		$passwordValue = $passwField->getValue();
		$confPasswValue = $confPasswField->getValue();
		if ($passwordValue != $confPasswValue) {
            $confPasswField->addError($this->translator->trans(
                "The password and the confirmation password don't match", array(), 'Shop.Notifications.Error'
            ));
        }

 

Now upload those 2 files in:

/override/classes/form/

Clear the cache

That's it!

 

Share this post


Link to post
Share on other sites

works perfectly except for translations. I used default catalogue translations (all translated already) but there is no any appropriate translation for "The email and the confirmation email don't match", it should be added to translations, can somebody help us to solve this problem, or did i miss something?

Prestashop 1.7.2.1

Edited by Marksaa (see edit history)

Share this post


Link to post
Share on other sites
On 4/18/2019 at 6:53 PM, mma87 said:

Hello,

I'm using PS 1.7.5.1 and I made a customization to insert email and password confirmation:

BACKUP FIRST!!

 

Download those 2 files


/classes/form/CustomerFormatter.php

/classes/form/CustomerForm.php

open the file CustomerFormatter.php and search


$format['email'] = (new FormField())

paste above


	$format['email'] = (new FormField())
            ->setName('email')
            ->setType('email')
            ->setLabel(
                $this->translator->trans(
                    'Email', [], 'Shop.Forms.Labels'
                )
            )
            ->setRequired(true)
        ;

this code:


		$format['conf_email'] = (new FormField)
			->setName('conf_email')
			->setLabel(
				$this->translator->trans(
					'Confirm e-mail', [], 'Shop.Forms.Labels'
				)
			)
			->setRequired(true)
		;

Then after:


        if ($this->ask_for_new_password) {
            $format['new_password'] = (new FormField())
                ->setName('new_password')
                ->setType('password')
                ->setLabel(
                    $this->translator->trans(
                        'New password', [], 'Shop.Forms.Labels'
                    )
                )
            ;
        }

paste this code:


		$format['conf_password'] = (new FormField)
			->setName('conf_password')
			->setType('password')
			->setLabel(
				$this->translator->trans(
					'Confirm password', [], 'Shop.Forms.Labels'
				)
			)
			->setRequired(true)
		;

 

Now open CustomerForm.php and search 


public function validate()

after this code:


	$emailField = $this->getField('email');
        $id_customer = Customer::customerExists($emailField->getValue(), true, true);
        $customer = $this->getCustomer();
        if ($id_customer && $id_customer != $customer->id) {
            $emailField->addError($this->translator->trans(
                'The email is already used, please choose another one or sign in', array(), 'Shop.Notifications.Error'
            ));
        }

Paste the following code:


//Confirm Email - check if is the same
		$confEmailField = $this->getField('conf_email');
		$emailValue = $emailField->getValue();
		$confEmailValue = $confEmailField->getValue();
		if ($emailValue != $confEmailValue) {
            $confEmailField->addError($this->translator->trans(
                "The email and the confirmation email don't match", array(), 'Shop.Notifications.Error'
            ));
        }
		

		//Confirm password - check if is the same
		$passwField = $this->getField('password');
		$confPasswField = $this->getField('conf_password');
		$passwordValue = $passwField->getValue();
		$confPasswValue = $confPasswField->getValue();
		if ($passwordValue != $confPasswValue) {
            $confPasswField->addError($this->translator->trans(
                "The password and the confirmation password don't match", array(), 'Shop.Notifications.Error'
            ));
        }

 

Now upload those 2 files in:


/override/classes/form/

Clear the cache

That's it!

 

ty for ur solution but still it give me an error
"

Parse error: syntax error, unexpected '$emailValue' (T_VARIABLE)

"
on CustomerForm.php

Any ideas how to solve it?



prestashop 1.7.5

Edited by legioxroma
mistake. (see edit history)

Share this post


Link to post
Share on other sites

Well it works, but I cannot translate those labels. I don't find it under translations. 

 

Share this post


Link to post
Share on other sites

Just applied your code and it works well so far. But I also don't find where to set some translations. Any idea? Thanks!

Share this post


Link to post
Share on other sites

Hello, I once used that code and it works well. But now I found out that it is not possible to have guest orders in the shop because if password confirmation field is not filled a message to fill it appears. How to achieve that both fileds - password and password confirmation - are optional? So thet it is also possible to order as guest without opning an account?

Thanks in advance!

Share this post


Link to post
Share on other sites
On 1/10/2020 at 4:07 PM, miographix said:

Hello, I once used that code and it works well. But now I found out that it is not possible to have guest orders in the shop because if password confirmation field is not filled a message to fill it appears. How to achieve that both fileds - password and password confirmation - are optional? So thet it is also possible to order as guest without opning an account?

Thanks in advance!

Yeah thats true, anyone find a solution?

Share this post


Link to post
Share on other sites

My solution was to change ">setRequired(true)" in CustomerFormatter.php to ">setRequired(false)". But only for the confirmation field!

  • Like 1

Share this post


Link to post
Share on other sites
14 minutes ago, miographix said:

My solution was to change ">setRequired(true)" in CustomerFormatter.php to ">setRequired(false)". But only for the confirmation field!

works great, thank You!

Share this post


Link to post
Share on other sites

Hello,

for me it also works very well in the PS 1.7.6.2 version. Thanks mma87!!

Unfortunately, like the others, I have the problem with the translation in other languages. Has anyone found a solution? Thank you.

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More