cakephp icon indicating copy to clipboard operation
cakephp copied to clipboard

cakePHP3: create an input password with empty field.

Open caBBAlainB opened this issue 12 years ago • 9 comments

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

caBBAlainB avatar Nov 19 '14 16:11 caBBAlainB

Have you tried without defining a "placeholder"?

thaJeztah avatar Nov 19 '14 17:11 thaJeztah

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 avatar Nov 19 '14 17:11 ADmad

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

HavokInspiration avatar Nov 19 '14 18:11 HavokInspiration

I opt for autocomplete=>off as default unless specified otherwise for password fields :)

dereuromark avatar Nov 19 '14 20:11 dereuromark

@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 avatar Nov 19 '14 21:11 HavokInspiration

@HavokInspiration I believe @dereuromark is just stating what he normally does in his apps, not suggesting that change to be made to core.

ADmad avatar Nov 19 '14 21:11 ADmad

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

HavokInspiration avatar Nov 19 '14 21:11 HavokInspiration

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.

ADmad avatar Nov 19 '14 21:11 ADmad

Hi, You are absolutely right, 'autocomplete' => 'off', fix the problem.

Thks

caBBAlainB avatar Nov 20 '14 08:11 caBBAlainB