如何使用 Html 标签创建 Yii2 Active Form 自定义消息?我通过更改此消息jQuery.activeForm
。
这是我正在尝试的 javascript 代码:
myform.js
- 其中包括AppAssets.php
.
操作顺序:
- 在浏览器上:通过 jQuery 验证电子邮件
- 在服务器上:验证电子邮件、验证电子邮件是否存在、是否存在不良用户列表等等...... - 这些功能正在运行
ajax/is-email-busy
。我通过 Ajax 查询来完成 - 在浏览器上:如果该邮箱已经注册并且是好用户的邮箱,则更改消息
在浏览器上:当用户单击消息中的链接时,将弹出登录表单
$("#form-ad").on("afterValidateAttribute", function(event, attribute, messages) { var hasError = messages.length !== 0; var field = $(attribute.container); var input = field.find(attribute.input); if(attribute.name == 'email' && !hasError) { var form_data = new FormData(); form_data.append('email', input.val()); $.ajax({ url: 'ajax/is-email-busy', dataType: 'json', cache: false, contentType: false, processData: false, data: form_data, type: 'post', success: function(data) { console.log(data); jQuery('#form-ad') .yiiActiveForm( 'updateAttribute', 'adform-email', ['This email is busy. If it\'s your email <a href="#">click here</a>']); } }); } });
在视图文件中:
echo $form->field($model, 'email')->input('email');