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
Posted (edited)

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
Posted (edited)
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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

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