Validate before Post

Validate before Post

Hi,


I am using the following code for signup form. It was just a simple posting and showing error using speedopopup and everything was fine. Now I want to add jquery validation before posting to make sure fields are entered and email field is validated. I added the below validate code from the validate plugin but nothing is happening. It’s just ignoring that part and jumping to the $.post?

How can I fix it please?

  1. <form name="frmSignup" id="frmSignup" method="post" action="signup">
  2. <table align="center" cellspacing="20" cellpadding="0" style="width: 300px; float: right;">
  3. <tr><td align="center" style="padding: 5px;"><h1>SIGN UP</h1></td></tr>
  4. <tr><td align="center" valign="middle"><input type="text" name="txtSignupName" id="txtSignupName" style="width: 100%; text-align: center; direction: ltr;" maxlength="200" placeholder="Your Name" autocomplete="off" required></td></tr>
  5. <tr><td align="center" valign="middle"><input type="text" name="txtSignupLoginID" id="txtSignupLoginID" style="width: 100%; text-align: center; direction: ltr;" maxlength="200" placeholder="Student ID" autocomplete="off" required></td></tr>
  6. <tr><td align="center" valign="middle"><input type="email" name="txtSignupEmail" id="txtSignupEmail" style="width: 100%; text-align: center; direction: ltr;" placeholder="Email Address" autocomplete="off" required></td></tr>           
  7. <tr><td align="center" valign="middle"><button id="btnSignup" type="submit" style="width: 100%;">Sign up</button></td></tr>
  8. <tr><td align="center" valign="middle"><button id="btnGotoSignin" type="button" style="width: 100%;">Sign in</button></td></tr>
  9. </table>
  10. </form>

   

  1.                 $('#frmSignup').validate({
  2.                                 rules: {
  3.                                 "txtSignupName": {
  4.                                                 required: "hellooooo" }
  5.                                 }
  6.                 }); //
  7.  
  8.  
  9.                 // post sign up;
  10.                 $('#btnSignup').click(function()
  11.                 {
  12.                                 $.post
  13.                                 (
  14.                                                 'signup',
  15.                                                 {
  16.                                                                 'name': $('#txtSignupName').val(),
  17.                                                                 'user': $('#txtSignupLoginID').val(),
  18.                                                                 'email': $('#txtSignupEmail').val()
  19.                                                 },
  20.                                                 function(data)
  21.                                                 {
  22.                                                                 if (data == "success")
  23.                                                                 {
  24.                                                                                 $.fn.speedoPopup(
  25.                                                                                 {
  26.                                                                                                 theme: "light",
  27.                                                                                                 caption: "Sign up",
  28.                                                                                                 effectIn: "fade",
  29.                                                                                                 htmlContent: "Thank you.<br><br>An administrator will review and activate your account shortly.",
  30.                                                                                                 onClose: function ()
  31.                                                                                                 {
  32.                                                                                                                 $('#signup').hide("slow");
  33.                                                                                                                 $('#signin').show("slow");
  34.                                                                                                 }
  35.                                                                                 });
  36.                                                                 }
  37.                                                                 else
  38.                                                                 {
  39.                                                                                 $.fn.speedoPopup(
  40.                                                                                 {
  41.                                                                                                 theme: "light",
  42.                                                                                                 caption: "Sign up",
  43.                                                                                                 // autoClose: 8000,
  44.                                                                                                 effectIn: "fade",
  45.                                                                                                 htmlContent: "<b>ERROR!</b><br><br>Failed to signup.<br><br>user already exist!."
  46.                                                                                 });
  47.                                                                 }
  48.                                                 }
  49.                                 );
  50.  
  51.                                 return false;
  52.                 });