Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Jquery validate plugin not working

struggling abit with the jquery valid plugin on my wordpress and need some help. help me identify anything that l am doing wrong. thanks in advance guys.

<form name="contactform" method="post" id="form" action="<?php echo get_template_directory_uri(); ?>/_form_to_email.php" class="cmxform" >
               <div class="article">
                <div class="" id="lookup_field" class="form-group">
            </div>
               <ul>
               <li>
               <div class="left-col">
                    <input name="firstName" id="firstname" type="text" class="input" placeholder="First Name"/>
               </div>

               <div class="right-col">
                    <input name="lastName"  id="lastname" type="text" class="input" placeholder="Last Name"/>
               </div>
               </li>
               <!-- postcode finder -->
                <li>
               <div class="left-col">
                    <input name="first_line" id="first_line" type="text" class="input" placeholder="Address line 1"  required />
               </div>

               <div class="right-col">
                    <input name="second_line" type="text" id="second_line"  class="input" placeholder="Address line 2" required/>
               </div>
               </li>

                <li>
               <div class="left-col">
                    <input name="postcode" id="postcode" type="text"  class="input" placeholder="Postcode" />
               </div>

               <div class="right-col">
                    <input name="post_town" id="post_town" type="text" class="input" placeholder="Town"/>
               </div>
               </li>

               <!-- postcode finder -->


               <li>
               <div class="left-col">
                    <input name="email" id="email" type="email" class="input" placeholder="Email" required />
               </div>

               <div class="right-col">
                    <input name="telephone" type="text"  class="input" placeholder="Telephone" pattern="[0-9]{3}[-][0-9]{3}[-][0-9]{4}"  title="Please provide a phone number in the following format: 0000-000-0000" required />
               </div>
               </li>

               <li>
               <div class="left-col">
                    <input name="mobile" id="mobile" type="text"  class="input" placeholder="Mobile" />
               </div>

               <div class="right-col">
                    <select name="select" class="select">
                         <option value="Drop nav" selected>Reason for Sale</option>
                         <option value="Option one">Option one</option>
                         <option value="Option Two">Option Two</option>
                    </select>
               </div>
               </li>

               <li>
               <div class="left-col">
                    <input name="value" type="text" placeholder="Current Property Value"class="input"  />
               </div>

               <div class="right-col">
                    <input name="mortgage" type="text" placeholder="Total of mortgages & secured loans"class="input"/>
               </div>
               </li>
               </ul>
               <a href="#codepopup" class="btn fancybox submit" type="submit" id="submit" name="sendMessage" value="submit">Submit</a>
               </div>
          </form>

2 Answers

Patricia Silva
PLUS
Patricia Silva
Courses Plus Student 89,123 Points

What is the error that you are getting? Also, provide the contents of your validate function.

Thanks.

the validation simply wont work. and yeah sure would do thanks

       $(document).ready(function() {
          $("#form").validate({
            firstname: "required",
            lastname: "required",
            post_town: "required",
            postcode: "required",
            mobile: "required",
            email: {
              required: true,
              email: true
            },
            messages: {
              firstname: "Please enter your firstname",
              lastname: "please enter your",
              post_town: "please enter your town",
              postcode: "please enter your postcode",
              moile: "please enter your mobile number"
            }
          });
         });

and l have included the javascript on my page like so

<script src="<?php echo get_template_directory_uri(); ?>/dist/jquery.validate.min.js">
Patricia Silva
Patricia Silva
Courses Plus Student 89,123 Points

I'm assuming the theme you are using is enqueuing the jquery validation plugin and that's why you are using the code above to include the javascript on your page.

if that's the case why are you not using this format <script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/jquery-1.3.2.min.js"></script>