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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

PHP Form with Bootstrap Validation

  • 30-10-2017 6:35pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 6,262 ✭✭✭Buford T Justice


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

    Or
    window.location.reload()
    


  • Registered Users, Registered Users 2 Posts: 6,289 ✭✭✭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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 Posts: 6,262 ✭✭✭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