使用 ActiveForm 在 yii2 中的电子邮件和密码字段中自动完成关闭

Posted

技术标签:

【中文标题】使用 ActiveForm 在 yii2 中的电子邮件和密码字段中自动完成关闭【英文标题】:Autocomplete offf in email and password field in yii2 using ActiveForm 【发布时间】:2019-07-05 16:16:11 【问题描述】:

我在 yii2 中使用 Activeform 作为表单,我使用电子邮件和密码输入电子邮件和密码。但是我已经登录了电子邮件和密码,记住我而不是我的表单上的电子邮件和密码字段自动完成。 该代码如下:

所以请帮助使用 yii2 删除自动完成功能。 这是图片中发生的事情:

我已使用以下链接获取解决方案,但不适用于我: Yii: disable autofill of username and password fields on chrome

<div class="col-md-12 mb-0">
<?=$form->field($model, 'coupon_code', ['inputOptions' => ['autocomplete' => 'off'],'template' => ''
. '<div class="input-group mb-3 coupon_parent_div">'
. 'input'
. '<div class="input-group-append">'
. '<button type="button" id="coupon_btn" class="btn btn-md btn-secondary" onclick="cart_refresh();">Apply</button>'
. '</div>'
. '</div>'
. 'error'])
->textInput(['class' => 'form-control my_input_border', 'maxlength' => true, 'placeholder' => $model->getAttributeLabel('coupon_code')])?>
</div>
<div class="form-row">
<div class="col-md-3 mb-0">
<?= $form->field($model, 'cc_cvv')->passwordInput(['class' => 'form-control my_input_border', 'maxlength' => 5, 'placeholder' => 'CVV', 'autocomplete' => 'off'])->label(false) ?>
</div>
</div>
<div class="card credit_card_custom_css">
<div class="card-body">
<div class="form-row">
<div class="col-md-7 mb-0">
<?= $form->field($model, 'cc_name',['inputOptions' => ['autocomplete' => 'off']])->textInput(['class' => 'form-control my_input_border marginBottom15', 'maxlength' => true, 'placeholder' => $model->getAttributeLabel('cc_name')])->label(false) ?>
</div>
<div class="col-md-5 mb-0">
<?= $form->field($model, 'cc_number',['inputOptions' => ['autocomplete' => 'new-password']])->textInput(['class' => 'form-control my_input_border marginBottom15', 'maxlength' => true, 'placeholder' => $model->getAttributeLabel('cc_number')])->label(false) ?>
</div>

</div>
<div class="form-row">
<div class="col-md-3 mb-0">
<?= $form->field($model, 'cc_cvv',['inputOptions' => ['autocomplete' => 'new-password']])->passwordInput(['class' => 'form-control my_input_border marginBottom15', 'maxlength' => 5, 'placeholder' => $model->getAttributeLabel('cc_cvv')])->label(false) ?>
</div>
</div>
</div>
</div>

这是发生在我身上的图片:

请帮我解决这个问题。

【问题讨论】:

【参考方案1】:

现代浏览器将忽略登录字段上的Autocomplete="off"

如果网站为用户名和密码设置了 autocomplete="off" 字段,则浏览器仍会提供记住此登录信息,并且 如果用户同意,浏览器将在下一个自动填充这些字段 用户访问页面的时间。

见The autocomplete attribute and login fields

【讨论】:

感谢回答

以上是关于使用 ActiveForm 在 yii2 中的电子邮件和密码字段中自动完成关闭的主要内容,如果未能解决你的问题,请参考以下文章

Yii2 - ActiveForm ajax 提交

Yii2 ActiveForm 停止工作

yii2.0 Activeform表单部分组件使用方法

yii2.0 Activeform表单部分组件使用方法

创建时隐藏的Activeform字段,并在Yii2中更新时显示

yii2.0 Activeform表单部分组件使用方法