Jump to content

How to add Password confirm Field in 1.7 ?


Recommended Posts

  • 8 months later...
  • 1 month later...

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!

 

Link to comment
Share on other sites

  • 1 month later...

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)
Link to comment
Share on other sites

  • 2 weeks later...
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)
Link to comment
Share on other sites

  • 3 months later...
  • 3 months later...

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!

Link to comment
Share on other sites

  • 4 weeks later...
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?

Link to comment
Share on other sites

  • 2 months later...

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...