1

I started using the jquery plugin for validation and am puzzled why it's not working, here is my javascript code for it: "

$(document).ready(function() {
    $('#shipper_form').validate({
        errorLabelContainer: "#errors",
        rules: {
            email: {
                required: true,
                email: true
            },
            business: "required",
            address: {
                required: true,
            },
            zipcode: {
                required: true,
            },
            phone: {
                required: true,
            },
            contact_name: {
                required: true,
            },
        },
        messages : {
            email : "Required Email *",
            business : "Required Business *",
            address : "Required Address *",
            zipcode : "Required Zip Code*",
            phone : "Required Phone*",
            contact_name : "Required Contact Name*",
        },
        submitHandler: function (form) {
            return false;
        }
    });
});
</script>"

Form:

<div id="errors"></div>
      <form method="post" action="signup.php">
        <table cellspacing="4" cellpadding="4">
            <tr>
                <td>
                    <input type="text" id="email" name="email" style="width: 300px;" class="form-control placeholder" placeholder="Email Address">
                    <span id="email_success" class="glyphicon glyphicon-check" style="color: green; display: none;"></span>
                </td>
            </tr>
            <tr>
                <td>

                    <input type="text" id="business" name="business" style="width: 300px;" class="form-control placeholder" placeholder="Business Name or DBA">
                    <span class="glyphicon glyphicon-check" style="color: green; display: none;"></span>
                </td>
            </tr>
         </table>
     </form>

The error messages shows up for email, but not for business or any of the other ones, I'm not sure what I'm doing wrong. Thanks.

4
  • Where is your #shipper_form element? No element has that ID name... Commented Nov 22, 2013 at 20:15
  • Sorry about that, I left out the id to the form , which is "id=shipper_form", when I moved it over. Commented Nov 22, 2013 at 20:21
  • Please post your solution below as an answer. Commented Nov 22, 2013 at 21:41
  • Just noticed this, the jquery-validate was conflicting with another javascript file in my case, so I removed the other file when I need to use the validation. Commented Feb 12, 2014 at 22:16

1 Answer 1

4

In my case the validation was not working because both jquery.validate.js and jquery.validate.unobtrusive.js was added to the page. In that case validation was working in half of the pages and was not working in the other half.( By not working I mean; the form still gets validated correctly but no error message was shown. )

Removing the jquery.validate.unobtrusive.js from the page fixed the problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.