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

Edited by AyKay47
Link to comment
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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