Disable autocomplete in CakePHP form input field

I create the form input using the CakePHP form helper and some inputs (most of the time "username" and "password") are autocomplete when creating actions, login actions, etc. This is annoying. I assume they are more common, so the browser uses its cookies to try to complete the input.

Anyway .. how do I disable this?

In my opinion:

... echo $this->Form->input('username', array( 'label' => 'Please enter your username', 'class' => 'pure-u-1-2' )); echo $this->Form->input('password', array( 'label' => 'Please enter your password', 'class' => 'pure-u-1-2' )); ... 

What am I missing?

+5
source share
2 answers

You can specify the attributes that will be submitted to the form helper. Specify the attribute "autofill" and set its value to "off".

 ... echo $this->Form->input('username', array( 'label' => 'Please enter your username', 'class' => 'pure-u-1-2', 'autocomplete' => 'off' )); echo $this->Form->input('password', array( 'label' => 'Please enter your password', 'class' => 'pure-u-1-2', 'autocomplete' => 'off' )); ... 

Which leads to something like this for your HTML:

 <input name="data[Model][username]" autocomplete="off" class="pure-u-1-2" id="ModelUsername" type="text"> 

You can also do this on all forms, not just at every entrance. Just specify the same attribute and value in the form, create this:

 ... echo $this->Form->create('Model', array( 'class' => 'class', 'autocomplete' => 'off' )); 

This will give you something like this in your HTML:

 <form action=".../Model/Action" class="class" autocomplete="off" id="ModelActionForm" method="post" accept-charset="utf-8"> 

NOTE Multiple browsers will now ignore autocomplete = "off" or autocomplete = "false". The workaround is to put the hidden text and password field in front of all the other inputs in your form. The browsers will be filled with the ones you want to leave alone.

+4
source

The best solution is to use autocomplete = new-password

It works fine in Chrome and Firefox

Like this:

 $this->Form->input('password', array('type' => 'password', 'autocomplete' => 'new-password')); 
0
source

Source: https://habr.com/ru/post/1202348/


All Articles