Jump to content

How to validate contact form using java script?


MathiVel

Recommended Posts

Don't validate anything with JavaScript what you can validate with PHP. Just don't.

 

Edit: ... Of course, I'm implying that your JavaScript implemntation is not found on your server. If it was a server-side implementation of JS, then go ahead. If you mean the client-side JS with the Document Object Model, then forget about it.

Edited by Irate
Link to comment
Share on other sites

Don't validate anything with JavaScript what you can validate with PHP. Just don't.

 

Edit: ... Of course, I'm implying that your JavaScript implemntation is not found on your server. If it was a server-side implementation of JS, then go ahead. If you mean the client-side JS with the Document Object Model, then forget about it.

 

I think he means checking if the user actually input anything in the field when they press submit. If they didn't input anything it shows an error message on top of that field. This would be done with JavaScript, not PHP.

Link to comment
Share on other sites

I think he means checking if the user actually input anything in the field when they press submit. If they didn't input anything it shows an error message on top of that field. This would be done with JavaScript, not PHP.

 

This can be accomplished with PHP. You would just re-display the form if there were errors, populate it with the information submitted, and display the necessary error notices.

 

The only benefit of using a client-side solution, like JavaScript, is that the page doesn't need to be reloaded before the errors are displayed. JavaScript could display the errors on the fly. Just be aware that JavaScript can be turned off, so it's a good idea to also validate using a server-side solution like PHP.

Link to comment
Share on other sites

This can be accomplished with PHP. You would just re-display the form if there were errors, populate it with the information submitted, and display the necessary error notices.

 

The only benefit of using a client-side solution, like JavaScript, is that the page doesn't need to be reloaded before the errors are displayed. JavaScript could display the errors on the fly. Just be aware that JavaScript can be turned off, so it's a good idea to also validate using a server-side solution like PHP.

 

Yes but its always good to be double-careful ;) Plus if you don't use JS than it isn't very interactive and it keeps it basic.

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.