Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP Form with Bootstrap Validation

Options
  • 30-10-2017 7:35pm
    #1
    Registered Users Posts: 60 ✭✭


    I have a php bootstrap validation form that when submitted sends the details to a database. The form works nicely. I have the validation and the success working, I have all the details going to the database but my issue is with clearing the form. When I press submit, it all works well except for it doesn't clear the form. This is my code....CAN ANYONE PLEASE HELP!!!

    .on('success.form.bv', function(e) {
    $('#success_message').slideDown({ opacity: "show" }, "slow") // Do something ...
    $('#contact_form').data('bootstrapValidator').resetForm();

    // Prevent form submission
    e.preventDefault();

    // Get the form instance
    var $form = $(e.target);

    // Get the BootstrapValidator instance
    var bv = $form.data('bootstrapValidator');

    // Use Ajax to submit form data
    $.post($form.attr('action'), $form.serialize(), function(result) {
    console.log(result);
    }, 'json');
    });


Comments

  • Registered Users Posts: 6,250 ✭✭✭Buford T Justice


    $(this).closest('form').find("input[type=text], textarea").val("");
    

    Or
    window.location.reload()
    


  • Registered Users Posts: 6,012 ✭✭✭Talisman


    jQuery doesn't have a form reset method, you can use a native DOM method:
    document.getElementById("contact_form").reset();
    

    Or if you want to stay in jQuery land:
    $("contact_form")[0].reset();
    


  • Registered Users Posts: 60 ✭✭Nolic


    Talisman wrote: »
    jQuery doesn't have a form reset method, you can use a native DOM method:
    document.getElementById("contact_form").reset();
    

    Or if you want to stay in jQuery land:
    $("contact_form")[0].reset();
    

    My JavaScript would be very limited. Do I add one of these to the bottom of the code already provided by Bootstrap Validator?


  • Registered Users Posts: 60 ✭✭Nolic


    $(this).closest('form').find("input[type=text], textarea").val("");
    

    Or
    window.location.reload()
    

    My JavaScript would be very limited. Do I add one of these to the bottom of the code already provided by Bootstrap Validator?


  • Registered Users Posts: 6,250 ✭✭✭Buford T Justice


    You'd add it to the post request for submitting the form. Once the submission has completed correctly, that's the point where you'd want to clear the form i'd imagine


  • Advertisement
Advertisement