Results 1 to 7 of 7

Thread: jQuery validation

  1. #1
    Join Date
    May 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default jQuery validation

    Hi

    I'm trying to validate a few forms with jQuery but none works, even if at least one of them was working before. Here is the code:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      <title><?php echo $title['title']; ?></title>
      <base href="http://root.com/divdev/">
      <meta http-equiv="Content-Type" content="text/html; charset=Western (ISO-8895-1)" />
      <link rel="stylesheet" type="text/css" href="css/frontend.css">
      <script src="//code.jquery.com/jquery-1.9.1.js"></script>
      <script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
      <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>  
      <script src="jquery.validate.pack.js" type="text/javascript"></script>  
        
      <script type="text/javascript">  
      // When the browser is ready...
      $(function() {
      
        // Setup form validation on the #contactform element
        $("#contactform").validate({
        
            // Specify the validation rules
            rules: {
                contactname: "required",
                email: "required",
                subject: "required",
                message: "required"
              },
    
            // Specify the validation error messages
            messages: {
                contactname: "É obrigatório o preenchimento do seu nome",  
                email: "É obrigatório o preenchimento do seu email",  
                subject: "É obrigatório o preenchimento do assunto da mensagem",  
                message: "É obrigatório o preenchimento da mensagem"  
            ),
      
            submitHandler: function(form) {
                form.submit();
            }
            
        });  
     });  
      </script>  
    
      <script>
        $('#msg').ready(function () {
            setTimeout(function () {
            $('#msg').hide();
            window.location.href = goto;
          }, 3000);
        });
      });
      </script>
    
      <script>
      // When the browser is ready...
      $(function() {
      
        // Setup form validation on the #addlinkform element
        $("#addlinkform").validate({
        
            // Specify the validation rules
            rules: {
                category: "required",
                company: "required",
                description: "required",
                address: "required",
                county: "required",
                city: "required",
                state: "required",
                country: "required",
                phone: "required",
                email: "required",
                duration: "required"
              },
    
            // Specify the validation error messages
            messages: {
                category: "<?php echo $addlinkinfo['category']; ?>",
                company: "<?php echo $addlinkinfo['company']; ?>",
                email: "<?php echo $addlinkinfo['email']; ?>",
                description: "<?php echo $addlinkinfo['description']; ?>",
                address: "<?php echo $addlinkinfo['address']; ?>",
                county: "<?php echo $addlinkinfo['county']; ?>",
                city: "<?php echo $addlinkinfo['city']; ?>",
                state: "<?php echo $addlinkinfo['state']; ?>",
                country: "<?php echo $addlinkinfo['country']; ?>",
                duration: "<?php echo $addlinkinfo['duration']; ?>"
            },
            
            submitHandler: function(form) {
                form.submit();
            }
        });
      });
      </script>
    
      <script>
      // When the browser is ready...
      $(function() {
      
        // Setup form validation on the #registerform element
        $("#registerform").validate({
        
            // Specify the validation rules
            rules: {
                fname: "required",
                lname: "required",
                email: {
                    required: true,
                    email: true,
                },
                user: {
                    required: true,
                },
                pass1: {
                    required: true,
                },
                pass2: {
                      required: true, 
                      equalTo: "#pass1",
                }
              },
    
            // Specify the validation error messages
            messages: {
                fname: "<?php echo $regerror['fname']; ?>",
                lname: "<?php echo $regerror['lname']; ?>",
                email: {
                    required: "<?php echo $regerror['email']; ?>",
                    email: "<?php echo $regerror['valemail']; ?>",
                },
                user: {
                    required: "<?php echo $regerror['user']; ?>",
                },
                pass1: {
                    required: "<?php echo $regerror['pass1']; ?>",
                },
                pass2: {
                    required: "<?php echo $regerror['pass2']; ?>",
                    equalTo: "<?php echo $regerror['difpass']; ?>",
                },
            },
            
            submitHandler: function(form) {
                form.submit();
            }
        });
      });
      </script>
      
      <script>
            // Setup form validation on the #loginform element
            $("#loginform").validate({
        
            // Specify the validation rules
            rules: {
                user: "required",
                pass: "required"
              },
    
            // Specify the validation error messages
            messages: {
                user: "<?php echo $logerror['user']; ?>",
                pass: "<?php echo $logerror['pass']; ?>"
            },
            
            submitHandler: function(form) {
                form.submit();
            }
        });
      });
      </script>
      </head>
      <body>
    I keep all the validation code in the header seccion.

    Can any one help me please with this?

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    2,027
    Thanks
    16
    Thanked 315 Times in 313 Posts
    Blog Entries
    13

    Default

    Part of the problem could be that you're linking to 2 jQuery libraries and 2 validation scripts, which are probably conflicting.

    I'm not familiar with a jQuery validation pack/plugin but the scripts look a little 'off'. Your setup goes;
    - jQuery 1.9.1
    - validation pack/plugin
    - jQuery 1.3.2
    - validation pack/plugin
    - JavaScript call + validation specifics

    Whereas I'd expect to see;
    - jQuery 1.9.1
    - validation pack/plugin
    - JavaScript call + validation specifics

    Without any documentation, or a complete web page with form markup, all I can suggest is that you only use one version of the jQuery library and one version of the validation pack/plugin, with the JavaScript call below those. Use whichever very of the jQuery library is recommended for the validation plugin while troubleshooting, and then maybe try more recent ones while testing to ensure that library upgrades still work with that particular plugin.

    If you need more help, please provide links to the validation plugin source/documentation and a live, complete web page.
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  3. #3
    Join Date
    May 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank You. I don't know much about jQuery (and JavaScript), and that code was grabbed from the net, an I used it as I found it (with a couple of changes in the code to make it more readable. I hope it will solve the issue.

    Thank You

  4. #4
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    2,027
    Thanks
    16
    Thanked 315 Times in 313 Posts
    Blog Entries
    13

    Default

    I'm not sure what you expect us to do with such little information.

    You'll need to play detective and do some more research to provide us with the tools/knowledge to help you. At the moment, you haven't given us enough information to work with.

    Thoughts to get you started;

    - Revisit the website where you copied the code (you might need to retrace you steps to find it again but look for references to source websites and/or authors).

    - Look inside the validation plugin files for author/source website information, then visit the website to look for installation instructions and/or do a separate search on the author name and follow whatever links you discover to see if you can find a trail to suitable documentation.

    - Search on key lines of code from the JavaScript call (you might pull up related tutorials or documentation)

    You should be able to find more information if you look hard enough - appropriate documentation is the key here and even people who are comfortable with JavaScript appreciate a little guidance to familiarise themselves with somebody else's work.

    Lastly, when you post your findings, you should also provide all the source code for your website by way of an actual live link that utilises the validation plugin you've found. The JavaScript is referencing form fields that we, so far, know nothing about - we can't guess usage and implementation for you.
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  5. #5
    Join Date
    May 2013
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    It is solved. Thank You

  6. #6
    Join Date
    Jun 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I think the issue was this bit $(function() at the start of where you first embedded js goes. It should be $(function(dom).ready(){

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,135
    Thanks
    44
    Thanked 3,231 Times in 3,192 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by getitfaster View Post
    I think the issue was this bit $(function() at the start of where you first embedded js goes. It should be $(function(dom).ready(){
    As far as I know, $(function(dom).ready() is not valid javascript nor valid jQuery. The:

    Code:
    $(function(){
    	//code to execute on DOM ready
    });
    is valid jQuery shorthand for jQuery's:

    Code:
    $(document).ready(function(){
    	//code to execute on DOM ready
    });
    See also:

    http://api.jquery.com/ready/
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Help with jQuery form validation
    By reisve in forum JavaScript
    Replies: 7
    Last Post: 05-20-2013, 01:02 PM
  2. Replies: 1
    Last Post: 08-11-2012, 03:46 PM
  3. Field validation w/js and jquery
    By sme in forum JavaScript
    Replies: 2
    Last Post: 03-12-2012, 06:04 PM
  4. form validation with jquery
    By TwitterRooms in forum JavaScript
    Replies: 3
    Last Post: 01-29-2012, 10:36 PM
  5. How to ignore default text in jQuery validation?
    By Rain Lover in forum JavaScript
    Replies: 0
    Last Post: 02-19-2011, 08:37 PM

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
  •