Hello,
I'm having some problems with validation. I have a specific js file for my validation funcions.
But each time I change the name of the form to validate ( and update the form in the validation function of course ) it just stop working.
For example:
The Function:
- $(function () {
- // validate signup form on keyup and submit
- var validator = $("#signupform").validate({
- rules: {
- firstname: "required",
- lastname: "required",
- username: {
- required: true,
- minlength: 2,
- remote: "users.php"
- },
- password: {
- required: true,
- minlength: 5
- },
- password_confirm: {
- required: true,
- minlength: 5,
- equalTo: "#password"
- },
- email: {
- required: true,
- email: true,
- remote: "emails.php"
- },
- dateformat: "required",
- terms: "required"
- },
- messages: {
- firstname: "Enter your firstname",
- lastname: "Enter your lastname",
- username: {
- required: "Enter a username",
- minlength: jQuery.format("Enter at least {0} characters"),
- remote: jQuery.format("{0} is already in use")
- },
- password: {
- required: "Provide a password",
- rangelength: jQuery.format("Enter at least {0} characters")
- },
- password_confirm: {
- required: "Repeat your password",
- minlength: jQuery.format("Enter at least {0} characters"),
- equalTo: "Enter the same password as above"
- },
- email: {
- required: "Please enter a valid email address",
- minlength: "Please enter a valid email address",
- remote: jQuery.format("{0} is already in use")
- }
- },
- // set this class to error-labels to indicate valid fields
- success: function (label) {
- // set as text for IE
- label.html(" ").addClass("checked");
- }
- });
- });
The HTML Code:
- <form class="form-horizontal well" id="signupform" action="#">
- <fieldset>
- <div class="control-group">
- <label class="control-label">First Name</label>
- <div class="controls">
- <input id="firstname" name="firstname" type="text" class="span2"/>
- </div>
- </div>
- <div class="control-group">
- <label class="control-label">Last Name</label>
- <div class="controls">
- <input id="lastname" name="lastname" type="text" class="span4">
- </div>
- </div>
- <div class="control-group">
- <label class="control-label">Username</label>
- <div class="controls">
- <input id="username" name="username" type="text" class="span6"/>
- </div>
- </div>
- <div class="control-group">
- <label class="control-label">Password</label>
- <div class="controls">
- <input id="password" name="password" type="password" class="span8"/>
- </div>
- </div>
- <div class="control-group">
- <label class="control-label">Confirm Password</label>
- <div class="controls">
- <input id="password_confirm" name="password_confirm" type="password" class="span8"/>
- </div>
- </div>
- <div class="control-group">
- <label class="control-label">Email Address</label>
- <div class="controls">
- <input id="email" name="email" type="text" class="span8"/>
- </div>
- </div>
- <div class="control-group">
- <div class="controls">
- <label id="lterms" for="terms">
- <input id="terms" type="checkbox" name="terms"/> I have read and accept the Terms of Use.</label>
- </div>
- </div>
- </fieldset>
- <div class="form-actions">
- <button class="btn btn-primary" type="submit">Save changes</button>
- <button class="btn">Cancel</button>
- </div>
- </form>
Using this scheme with the form name
signupform everything goes smooth. The problem is that if I change the name.
For example:
Function File:
- var validator = $("#registerform").validate({
The code File:
- <form class="form-horizontal well" id="registerform" action="#">
I only change the name and everything stops works ( all code in js file and html remains the same ).
I would like to get some help in solve this problem because I need more forms validated with custom fields, and none of them work.
Anyone could help please?