需要帮助修改表单JS脚本以添加成功消息

时间:2014-03-13 01:41:08

标签: javascript jquery forms jquery-validate

我需要帮助修改此脚本以添加将在页面上的div中显示的成功消息。如果有一种方法可以在提交表单后隐藏提交按钮,这将有助于防止人们一遍又一遍地发送垃圾邮件。

$().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",
        },

    });

});

1 个答案:

答案 0 :(得分:1)

您似乎正在使用jQuery Validation插件。将其添加到配置对象:

validate({
  rules: ...
  messages: ...
  submitHandler: function(form) {
    $('#submitButton').prop('disabled', true);
    $('#successMessage').text('Success message!');
    form.submit();
  }
});

(替换您自己的元素以获取提交按钮ID和将接收成功消息的空元素的ID)。

编辑:哎呀,错了。