为什么即使消息未发送,我的提交按钮也会隐藏?

Why is my submit button hiding even when the message don't get sent?

知道为什么我的提交按钮无论如何都会隐藏(消息已成功发送或未发送)。

当消息未发送时,我可以看到 #error_message 出现(这是正常的)但我希望提交按钮仍然可见(以允许用户再试一次)

谢谢

$(document).ready(function() {

        $('#contact_form').bootstrapValidator({
            feedbackIcons: {
                valid: 'fa fa-check',
                invalid: 'fa fa-times',
                validating: 'fa fa-refresh'
            },
            fields: {
                first_name: {
                    validators: {
                            stringLength: {
                            min: 2,
                        },
                            notEmpty: {
                            message: 'Veuillez indiquer votre prénom'
                        }
                    }
                },
                 last_name: {
                    validators: {
                         stringLength: {
                            min: 2,
                        },
                        notEmpty: {
                            message: 'Veuillez indiquer votre nom'
                        }
                    }
                },
                email: {
                    validators: {
                        notEmpty: {
                            message: 'Veuillez indiquer votre adresse e-mail'
                        },
                        regexp: {
                        regexp: '^[^@\s]+@([^@\s]+\.)+[^@\s]+$',
                        message: 'Veuillez indiquer une adresse e-mail valide'
                                }
                    }
                },
                message: {
                    validators: {
                          stringLength: {
                            min: 10,
                            max: 1000,
                            message:'Votre message doit faire plus de 10 caractères et moins de 1000.'
                        },
                        notEmpty: {
                            message: 'Veuillez indiquer votre message'
                        }
                        }
                    }
                }}).on('success.form.bv', function (e) {
                e.preventDefault();
              $('button[name="submit"]').hide();

              var bv = $(this).data('bootstrapValidator');
              // Use Ajax to submit form data
              $.post($(this).attr('action'), $(this).serialize(), function (result) {
                  if (result.status == 1) {
                      $('#success_message').slideDown({
                          opacity: "show"
                      }, "slow")
                      $('#contact_form').data('bootstrapValidator').resetForm();
                  } else {
                        $('#error_message').slideDown({
                          opacity: "show"
                      }, "slow")              }
              }, 'json');
          }
            );

    });

你按下提交后隐藏了它$('button[name="submit"]').hide();

发生错误时您可以再次显示该按钮

$.post($(this).attr('action'), $(this).serialize(), function (result) {
    if (result.status == 1) {
        $('#success_message').slideDown({
            opacity: "show"
        }, "slow")
        $('#contact_form').data('bootstrapValidator').resetForm();
    } else {
        $('#error_message').slideDown({
            opacity: "show"
        }, "slow")     
        // show the button again
        $('button[name="submit"]').show();         
    }
}, 'json');