Abhilash
Abhilash

Reputation: 104

show password in field in zend framework 2

i have a form which in edit mode. we need customers to enter password for their account here. So first time password field comes blank. which is alright.

But after saving the form when we again take that record to edit, the password field still shows as blank. i tried to find all the values that i am getting from form array using code "$form->get('sDbPassword')". buts its showing "[value:protected] =>". its not even showing that its have some value in that field.

Need some help. i am a newbie in zend framework 2.

thanks in advance.

Upvotes: 0

Views: 932

Answers (1)

ins0
ins0

Reputation: 3928

this is normal because zend don't populate values for form elements with type Zend\Form\Element\Password for security reasons. so after your customer submit the form with the password, the value can received after form validation $form->isValid() with $form->getData().

in order to populate the password you can't use $form->populateValues($this->getRequest()->getPost()) to fill in the form element password value, zend will ignore this password element.

so after save you grab the password and pass it to the view directly $viewModel->setVariable('pwd', $formData['userPassword']); and pass it into the input element manually.

in your view element then

<input type="password" value="<?php echo $this->pwd; ?>" name="userPassword" />

but i don't recommend this procedure. the password should be a solid security wall, don't place a ladder infront of this wall.

Upvotes: 2

Related Questions