Jump to content

Possible bug with HelperForm and password type fields


Recommended Posts

Hi all, I'm facing a problem with the HelperForm and an input of password type: I'm developing a module for PrestaShop 1.6 with Bootstrap support and in my renderForm() method I declare my form fields like this:

$fields_form[0]['form'] = array(
			'legend' => array(
            			'title' => $this->l('Settings'),
	    			'icon' => 'icon-cogs'
        		),
        		'input' => array(	    
	    			// All my fields here
        		),
        		'submit' => array(
            			'title' => $this->l('Save'),
            			'class' => 'button pull-right'
        		)
    		);

One of these fields is an input of type password and I've declared it like this:

array(
'type' => 'password',
'label' => $this->l('Password'),
'desc' => $this->l('My pwd description'),
'name' => 'MY_PASSWORD',
'required' => true
)

And at the end of same method, just before the return statement, I load the current value like this:

$helper->fields_value['MY_PASSWORD'] = Configuration::get('MY_PASSWORD');

The problem is that when I enter in the configuration page of my module, the password field is rendered with the Bootstrap nice CSS, but it is always empty. If I write inside it and then I save settings it works (I mean I get no error) but when page reload that field is empty again. If I change is type as a common text field like this:

array(
'type' => 'text',
'label' => $this->l('Password'),
'desc' => $this->l('My pwd description'),
'name' => 'MY_PASSWORD',
'required' => true
)

the problem vanish and it work as intended. Thanks you all for your time and attention.

Link to comment
Share on other sites

  • 2 months later...

Seems like the field was designed to behave this way: you can only use the field to change a password... it never displays anything. So, you'll want to check for a value before updating the password field

 

I'm using something like this:

$password = strval(Tools::getValue('myPasswordId'));
if($password) {
  // only save if a value was entered
  Configuration::updateValue('passwordKey', $password);
}

Note: the password field shouldn't be "required", because it's only for updating.

 

It would be nice for the field to show something by default instead of just giving you an empty field. I might look into that when I get some time. 

Edited by numberMumbler (see edit history)
  • Confused 1
Link to comment
Share on other sites

×
×
  • Create New...