cakePHP3: create an input password with empty field.
Hello, I read in the doc the following note: "If you need to set the default value in a password field to blank, use ‘value’ => ‘’ instead."
First, I'm surprised to see this note in http://book.cakephp.org/3.0/en/views/helpers/form.html#options-for-select-checkbox-and-radio-inputs, and not later in http://book.cakephp.org/3.0/en/views/helpers/form.html#options-for-select-checkbox-and-radio-inputs for example.
So I tried it in my default.ctp file where I have nav bar including login fields/button:
<?= $this->Form->input('password', array('label' => false, 'div' =>false, 'placeholder' =>__("Mot de passe"), 'class' => 'form-control', 'value' => '')); ?>
the html source code is:
But the password's field is still automatically filled in by the browser. I hoped this option could prevent this behavior.
It seems that it's the same thing with or without 'value' => ''.
Is it a misunderstanding?
Regards, Alain
Have you tried without defining a "placeholder"?
But the password's field is still automatically filled in by the browser
Did you save your login details in browser or have a browser extension which fills login forms? If so that's not something CakePHP can prevent.
@ADmad is most likely right.
Try to use the autocomplete attribute of the input and set if to off.
echo $this->Form->input('password', ['autocomplete' => 'off']);
This should prevent the browser from putting the credentials if they were saved.
I opt for autocomplete=>off as default unless specified otherwise for password fields :)
@dereuromark I don't really know if it's a good idea. I'm afraid this could be confusing at first ("why is my form not filling the password ?!"). I'll admit this can be as confusing as having it autocompleted even if the value is set to an empty string.
Maybe updating the doc to explain the special case for inputs with type password ?
@HavokInspiration I believe @dereuromark is just stating what he normally does in his apps, not suggesting that change to be made to core.
@ADmad @dereuromark Oh, my bad then. Although having an explanation in the documentation could avoid confusion, unless this goes beyond Cake's "scope" (which in a sense, is, as this does not really have anything to do with Cake and is purely a HTML issue).
This is beyond Cake's scope imo.
I am closing this as I don't think there's any bug in Cake's code. Can revisit if more info is provided by OP.
Hi, You are absolutely right, 'autocomplete' => 'off', fix the problem.
Thks