jquery - javascript validator not working, just returning it passed when it didn't -
here code, compared site has script working , can't seem spot difference why mine not working. missing simple.
this site got script instructions little vague: http://rickharrison.github.io/validate.js/
this working example: http://www.boutiqueapartments.com/index.php/contact/test
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <!-- main style sheet--> <link rel="stylesheet" type="text/css" href="stylesheets/stylesheet.css"/> <!-- validation script--> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script> <script type="text/javascript" src="../bugs/javascript/validate.min.js"></script> <title></title> </head> <body> <div class="success_box">all of fields validated!</div> <div class="error_box"></div> <div id="container"> <form name="create_bug" id="create_bug" method="post" action="bug_create.php" onsubmit="return formvalidator()"> <div class="fm-req"> <label for="bug_description">bug title:</label> <input type="text" name="bug_title" id="bug_title" value="" size="78" maxlength="250"> </div> <input type="submit" name="formsubmit" value="submit"> </form> </div> <script type="text/javascript"> new formvalidator('create_bug', [{ name: 'bug_title', display: 'bug title', rules: 'required' }], function(errors, event) { var selector_errors = $('.error_box'), selector_success = $('.success_box'); if (errors.length > 0) { selector_errors.empty(); selector_errors.append(errors.join('<br />')); selector_success.css({ display: 'none' }); selector_errors.fadein(200); } }); </script> </body> </html>
all returned if blank "all fields have passed" or "object object", ideas going wrong?
the errors object array, can't simple join. try
new formvalidator('create_bug', [ { name : 'bug_title', display : 'bug title', rules : 'required' } ], function(errors, event) { var selector_errors = $('.error_box'), selector_success = $('.success_box'); if (errors.length > 0) { var errorstring = ''; $.each(errors, function(i, e) { errorstring += e.message + '<br />'; }) selector_errors.empty(); selector_errors.html(errorstring); selector_success.css({ display : 'none' }); selector_errors.fadein(200); } });
and fiddle here.
Comments
Post a Comment