SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript Validate Form Not running

    I tried using the Javascript error in page code found here

    However when implemented into my form the validation no longer works and I believe that the page isn't picking up to run the javascript like it should when the form submits.

    Code:
    <form id="UserAddForm" method="post" action="" accept-charset="utf-8" name="UserAddForm"><div style="display:none;"><input type="hidden" name="_method" value="POST" /></div>
        
    <div id='UserAddForm_errorloc' class='error_strings'></div> 
    
        <h1>Register</h1>
    
            <ul class="inputfields">
                <li>
                    <span>Username:</span>
    
                    <br />
                    <div class="input text"><input name="data[User][username]" type="text" maxlength="75" id="UserUsername" /></div>            </li>
                <li>
                    <span>Password:</span>
    
                    <br />
                    <div class="input password"><input type="password" name="data[User][password]" id="UserPassword" /></div>            </li>
                <li>
    
                    <span>Confirm Password:</span>
                    <br />
                    <input type="password" name="data[User][confirm_password]" id="UserConfirmPassword" />            </li>
                <li>
    
                    <span>E-mail:</span>
                    <br />
                    <div class="input text"><input name="data[User][email]" type="text" maxlength="75" id="UserEmail" /></div>            </li>
    
                <li>
                    <span>Display Name:</span>
                    <br />
                    <div class="input text"><input name="data[User][displayname]" type="text" maxlength="50" id="UserDisplayname" /></div>            </li>
    
            </ul>
    
        <div class="submit"><input type="submit"  value="Submit" />
        </div></form>
        <div id='UserAddForm_errorloc' class='error_strings'></div> 
        <script language="JavaScript" type="text/javascript">
      var frmvalidator  = new Validator("UserAddForm");
    
      frmvalidator.EnableOnPageErrorDisplaySingleBox();
      frmvalidator.EnableMsgsTogether();
      frmvalidator.addValidation("data[User][username]","req",
      "Please enter your Username");
     
      frmvalidator.addValidation("data[User][password]","req",
      "Please enter your Password");
      frmvalidator.addValidation("data[User][password]","minlen=6",
      "Min length is 6");
      
      frmvalidator.addValidation("data[User][confirm_password]","req",
      "Please confirm your Password");
      frmvalidator.addValidation("data[User][confirm_password]","minlen=6",
      "Min length is 6");
     
      frmvalidator.addValidation("data[User][email]","maxlen=50");
      frmvalidator.addValidation("data[User][email]","req",
      "Please enter your e-mail address");
      frmvalidator.addValidation("data[User][email]","email",
      "This is not a valid email address, please re-e);
     
      frmvalidator.addValidation("data[User][displayname]","req",
      "Please enter a Display Name");
    
    </script>
    This is the file controlling the submit function:
    http://www.javascript-coder.com/html...alidatorv31.js

    Of course I have my own copy on the server, but whenever I submit the form I created, nothing happens. It just submits without running the validation. Any help in this matter would be greatly appreciated!

  2. #2
    Non-Member
    Join Date
    Jan 2011
    Location
    Heaven
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Put an onsubmit event handler in your opening form tag which runs your validation function. The validation function must return either true or false. If it returns true (meaning all form data is valid) the form will be submitted. If it returnd false, the form will not be submitted.

    Google onsubmit if you haven't used it before.

  3. #3
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The issue is that you aren't supposed to have to do that from the documentation. The example provided does not use the onSubmit event handler.

    Example Shown Here

    Supposedly the genvalidator file overrides the onSubmit function.

  4. #4
    SitePoint Addict bronze trophy AllanP's Avatar
    Join Date
    Sep 2010
    Location
    Australia
    Posts
    298
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    There are errors in the javascript file for example:

    Error: frmvalidator.EnableOnPageErrorDisplaySingleBox is not a function

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2009
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is an incomplete string
    Code:
    frmvalidator.addValidation("data[User][email]","email",
      "This is not a valid email address, please re-e);
    If the script gen_validatorv31.js is linked properly, it should work fine.

    The attached file contains the corrected code
    Attached Files Attached Files


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •