0

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"
    }

});
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295
zod
  • 12,092
  • 24
  • 70
  • 106

3 Answers3

0

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

Teja Kantamneni
  • 17,402
  • 12
  • 56
  • 86
  • yes... after entering registration details ..show success another page thnks anyway – zod Aug 17 '10 at 21:07
0

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
  • 94,126
  • 40
  • 223
  • 295
  • 1
    `.validate()` calls `submitHandler`, calling it inside would cause an infinite loop, there's no need to call it in there. – Nick Craver Aug 17 '10 at 20:51
  • 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 Aug 17 '10 at 20:52
  • There's no need to check `.valid()` either, if you're running you're valid, otherwise you're in the `invalidHandler`:) – Nick Craver Aug 17 '10 at 21:20
  • @Nick haha - that's a good point. Looks like I've completely borked this up - fixing again. – Vivin Paliath Aug 17 '10 at 21:27
0

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

Robert
  • 21,110
  • 9
  • 55
  • 65