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

标签 javascript jquery css mysql yii2

我在 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>

这是发生在我身上的照片: enter image description here

请帮我解决这个问题。

最佳答案

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

If a site sets autocomplete="off" for username and password fields, then the browser will still offer to remember this login, and if the user agrees, the browser will autofill those fields the next time the user visits the page.

参见 The autocomplete attribute and login fields

关于javascript - 使用 ActiveForm 在 yii2 中的电子邮件和密码字段中自动完成关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54642934/

相关文章:

javascript - 如何根据我的 jinja for 循环创建多个动态选择器?

JavaScript 将 mouseenter 事件传递给另一个元素下方的元素

javascript - JS parseInt() 问题

css - 如何在 Bootstrap 3 中垂直对齐文本旁边的图标

html - 使用媒体查询的响应能力

css - 管理局部 View 的样式表

javascript - 使用 Angular 显示内容

javascript - c3.js 如何更新 chart.load() 上的 x 轴标签?

jquery - 类型 'jqGrid' 的值上不存在属性 'JQuery'

javascript - HTML脚本标签中的Petite-vue Init属性