knocked loose
knocked loose

Reputation: 3314

Stopping a refresh/redirect on form submission

I have an app that wants to redirect after submitting and I would like to freeze it after clicking submit. The app is a multiform that has an end slide that I would like the animation to trigger and then freeze it from redirect/refresh.

<form id="form" class="msform hs-form stacked hs-custom-form" accept-charset="UTF-8" 
action="confidential-url" enctype="multipart/form-data" method="POST" novalidate="">

<!-- form stuff -->

</form>

$(".submit").click(function () {
        return true;
        e.preventDefault();
    });

I have tried adding onSubmit="return false" to my <form> tag as well as various e.preventDefault(); methods. All of them will either:

• Cause it to prevent the redirect/refresh but not update the fields in the DB

• Update fields but page will still redirect

EDIT: After trying to do this in AJAX I found out that I was being blocked out from the external URL, thanks to to r4phG for helping me figure it out!

Upvotes: 0

Views: 204

Answers (1)

r4phG
r4phG

Reputation: 515

Is your submission causing your redirection/ refresh ?

If you have to submit your form to update fields in your database, you'll have to submit your form. But if you don't want to refresh all your page, you should think of using Ajax, as your submission will not refresh your page

Example from jquery ajax doc :

$("#form").submit(function() { 
      $.ajax({ 
             url:'confidential-url', 
             method:'POST' , 
             data:$(this).serialize() //submits your form information
      }); 
      return false; // prevent the server form submission 
});

jQuery ajax documentation

Upvotes: 4

Related Questions