4

how can i disable autofill fields in Yii. It automatically loads saved username and password of the logged in user.

<?php echo $form->textField($model,'username',array('size'=>60,'maxlength'=>100, 'class'=> 'form-control input-inline input-medium', 'autocomplete'=>"off")); ?>
<?php echo $form->passwordField($model,'password',array('size'=>60,'maxlength'=>255, 'class'=> 'form-control input-inline input-medium', 'autocomplete'=>"off")); ?>

NOTE: property autocomplete='off' does not work on chrome. It is working on FF.

aWebDeveloper
  • 31,131
  • 35
  • 150
  • 224
Talha Malik
  • 1,392
  • 3
  • 19
  • 41

8 Answers8

3

May be this one help:)

<div class="row">
 <div class="col-md-4">
    <?php echo $form->field($model, 'email',['inputOptions' => [
'autocomplete' => 'off']])?>
 </div>
<div class="col-md-4">
    <?php echo $form->field($model, 'password',['inputOptions' => [
'autocomplete' => 'off']])->passwordInput() ?>
 </div>
</div>
Kalpesh Desai
  • 1,307
  • 14
  • 16
  • Nice I add directly in the `ActiveForm:begin(['fieldConfig' => ['inputOptions' => ['autocomplete' => 'off']]]);` to apply it to the whole form – MoVod Mar 04 '20 at 04:59
3

Try this. It works in YII 2.0 for all fields.

<?php $form = ActiveForm::begin(['id' => 'form-name', 'options' => ['autocomplete' => 'off'],]); ?>
mr rogers
  • 2,734
  • 1
  • 17
  • 26
Indrajeet Singh
  • 2,717
  • 21
  • 24
0

Browser have decided to override autocomplete off for Login form (username & passwords). That could be in play here.

https://bugzilla.mozilla.org/show_bug.cgi?id=956906

http://www.theregister.co.uk/2014/04/09/chrome_makes_new_password_grab_in_version_34/

Try the tricks given in this answer

Chrome Browser Ignoring AutoComplete=Off

Community
  • 1
  • 1
aWebDeveloper
  • 31,131
  • 35
  • 150
  • 224
0

It appears that Chrome now ignores autocomplete="off" unless it is on the tag. Hope this Helps

user3111011
  • 145
  • 9
0
<?=
 $form->field($form_model, 'password',)
      ->textInput(['autocomplete' => 'off','placeholder'=>'Password'])
?>

just use ->textInput(['autocomplete' => 'off']) in front of field

Nico Haase
  • 6,670
  • 34
  • 28
  • 48
Ganesh Apune
  • 119
  • 6
0

Try this, works with text field in Chrome at date 30-Nov-2018:

<input type="text" name="whatever" autocomplete="off_<?php echo time() ?>">

This disabled the autofill on Chrome

0

Try it:

<?= $form->field($model, 'password_change')->passwordInput(['maxlength' => true, 'autocomplete' => 'new-password'])->label(App::t('Current password')) ?>
MjM
  • 498
  • 3
  • 11
0

I think you can add style class or attributes for textInput like this:

$form->field($model, 'plate_number')->textInput(['autocomplete' =>'off']);
navid
  • 650
  • 6
  • 13