[英]Need help modifying a form JS script to add a success message
I need help modifying this script to add a success message that would show in a div on the page. 我需要修改此脚本的帮助,以添加将在页面上的div中显示的成功消息。 If there is a way to hide the submit button as well after the form is submitted, that would be helpful in preventing folks from spamming the submit button over and over again.
如果在提交表单后还有一种隐藏提交按钮的方法,这将有助于防止人们一遍又一遍地发送垃圾邮件。
$().ready(function() {
// validate board form choices and submit
$("#custom_board_form").validate({
rules: {
firstname: {
required: true,
minlength: 2
},
lastname: {
required: true,
minlength: 2
},
email: {
required: true,
email: true
},
},
messages: {
firstname: {
required: "Please enter a name",
minlength: "Your name must consist of at least 2 characters"
},
lastname: {
required: "Please enter a name",
minlength: "Your name must consist of at least 2 characters"
},
email: "Please enter a valid email address",
},
});
});
You seem to be using jQuery Validation plugin. 您似乎正在使用jQuery Validation插件。 Add this to your configuration object:
将此添加到您的配置对象:
validate({
rules: ...
messages: ...
submitHandler: function(form) {
$('#submitButton').prop('disabled', true);
$('#successMessage').text('Success message!');
form.submit();
}
});
(replacing your own elements for the submit button ID and the ID of an empty element that will receive the success message). (将您自己的元素替换为提交按钮ID和将接收成功消息的空元素的ID)。
EDIT: Oops, wrong hook. 编辑:糟糕,错误的钩子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.