views:

168

answers:

4

I am using jquery for validation set some rules.

If validation success I want to redirect to another page. How can I do it?

// validate contact form on keyup and submit
$("#contactForm").validate({
    //set the rules for the field names
    rules: {
        name: {
            required: true,
            minlength: 2
        },
        email: {
            required: true,
            email: 4
        },

    },
    //set messages to appear inline
    messages: {
        name: "Please enter your name",
        password: "Please enter your email"
    }

});
A: 

Add your redirect logic in submitHandler callback. I think you want to set the window.url to a diff url. right?

Teja Kantamneni
yes... after entering registration details ..show success another pagethnks anyway
zod
A: 

Hope this answers your question, not jquery specific, but just call it when your validation is done.

http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery

omarello
A: 

Try adding a submitHandler option to validate like so:

$("#contactForm").validate({
   ...
   submitHandler: function(form) {    
      window.location = "http://your.url.here";
   }   
});

So when you validate the form, submitHandler is called if the form validated successfully, and there you redirect the user.

Vivin Paliath
`.validate()` calls `submitHandler`, calling it inside would cause an infinite loop, there's no need to call it in there.
Nick Craver
Thanks Nick. Fixing it now. The documentation suggested that `validate()` be called before `valid()`. I didn't realize that calling `validate()` by itself also calls `submitHandler`.
Vivin Paliath
@Vivin - There's no need to check `.valid()` either, if you're running you're valid, otherwise you're in the `invalidHandler`:)
Nick Craver
@Nick haha - that's a good point. Looks like I've completely borked this up - fixing again.
Vivin Paliath
A: 

Call window.location.replace='http://www.newpage.com';. Not jQuery specific.

Robert