Laura555 Posted February 21, 2013 Share Posted February 21, 2013 I have just started trying to validate my register form on my website. I have entered the following code but it's not working so if anyone has any suggestions as to what I need to change, please let me know <form action='' method='POST'> <p><b>Name:</b><br /><input type='text' name='Name'/> <p><b>Phone No:</b><br /><input type='text' name='PhoneNo'/> <p><b>Password:</b><br /><input type='password' name='password'/> <p><b>Username:</b><br /><input type='text' name='username'/> <br> <br> <br> <p><input type='submit' class="submit_btn float_l" value='Register' /><input type='hidden' value='1' name='submitted' /> </form> <script type="text/javascript"> var frmvalidator = new Validator("register"); frmvalidator.addValidation("Name","req","Please enter your Name"); frmvalidator.addValidation("Name","maxlen=20", "Max length for Name is 20"); frmvalidator.addValidation("PhoneNo","maxlen=50"); frmvalidator.addValidation("PhoneNo","numeric"); frmvalidator.addValidation("password","req"); frmvalidator.addValidation("password","maxlen=20"); frmvalidator.addValidation("username","req"); frmvalidator.addValidation("username","maxlen=20"); validator.EnableOnPageErrorDisplay(); validator.EnableMsgsTogether(); </script> Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted February 21, 2013 Share Posted February 21, 2013 You are mixing javascript and PHP together. This simply will not work since each script is executed at different times. All validation should be done server side. Quote Link to comment Share on other sites More sharing options...
Stefany93 Posted February 21, 2013 Share Posted February 21, 2013 You are mixing javascript and PHP together. This simply will not work since each script is executed at different times. All validation should be done server side. I fail to see how he is mixing PHP and JS together... Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted February 21, 2013 Share Posted February 21, 2013 (edited) I fail to see how he is mixing PHP and JS together... I fail to see how your post was helpful in any way. The first part of my response aside, form validation should be executed server side primarily, with javascript as a secondary layer over the server side validation. That was really the point I was trying to convey. Edited February 21, 2013 by AyKay47 Quote Link to comment Share on other sites More sharing options...
Stefany93 Posted February 22, 2013 Share Posted February 22, 2013 I fail to see how your post was helpful in any way. The first part of my response aside, form validation should be executed server side primarily, with javascript as a secondary layer over the server side validation. That was really the point I was trying to convey. Oh, did you mean that the author SHOULD mix PHP and JS together? I seem to have understood it wrong, I thought you said that he is currently mixing them... Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 22, 2013 Share Posted February 22, 2013 form validation should be executed server side primarily, with javascript as a secondary layer over the server side validation. All validation should be done server side. I see what you're saying, sure. .... OP, if you still have an issue please post with more details. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted February 22, 2013 Share Posted February 22, 2013 I see what you're saying, sure. .... I'm not sure how to respond to that. Quote Link to comment Share on other sites More sharing options...
rwhite35 Posted February 22, 2013 Share Posted February 22, 2013 At the risk of stating the obvious, I'll assume you have included you javascript up in the head with something like: <script src="gen_validatorv4.js" type="text/javascript"></script> Your form needs an id, something like <form action='' method="post" id="myform"> Then you call your class with: var frmvalidator = new Validator("myform"); And as was stated above, this is client-side validation, you'll still need to scrub your input on the server-side, and that's where the PHP will come in handy. Good luck, Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.