简体   繁体   中英

Yii: disable autofill of username and password fields on chrome

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.

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>

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

<?php $form = ActiveForm::begin(['id' => 'form-name', 'options' => ['autocomplete' => 'off'],]); ?>

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

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

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

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

尝试一下:

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

我认为您可以为 textInput 添加样式类或属性,如下所示:

$form->field($model, 'plate_number')->textInput(['autocomplete' =>'off']);

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM