Jump to content

Validation of form


Laura555

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/274762-validation-of-form/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/274762-validation-of-form/#findComment-1414046
Share on other sites

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...

Link to comment
https://forums.phpfreaks.com/topic/274762-validation-of-form/#findComment-1414132
Share on other sites

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. 

Link to comment
https://forums.phpfreaks.com/topic/274762-validation-of-form/#findComment-1414141
Share on other sites

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,

Link to comment
https://forums.phpfreaks.com/topic/274762-validation-of-form/#findComment-1414170
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.