How do I make certain fields required in my simple contact form. I guess I also need to know how to display a message to fill out ALL fields if the user tries to send the form without doing so.
Thanks in advance
Kit
| SitePoint Sponsor |
How do I make certain fields required in my simple contact form. I guess I also need to know how to display a message to fill out ALL fields if the user tries to send the form without doing so.
Thanks in advance
Kit





You can use Javascript to check upon form submit that all appropriate values are filled in, but that will fail if the user has JS turned off. Other than that you will have to rely on server-side scripting, like PHP to check.
█ Nick . all that we see or seem, is but a dream within a dream
█ Show someone you care, send them a virtual flower.
█ Good deals on men's watches

If you have Dreamweaver, there is a series of tools called Spry that will very easily let you make your contact fields required.
If not, simply search "javascript, form field required" and you'll get tons of results.
What I usually do is run two scripts, one for JavaScript (client-side) and another for PHP (server-side). Client-side validation is good if your interested in user friendliness and bandwidth, though not required. Server-side validation you have to do unless you'll get a gaping security hole. Possibility said and implied most of this, but I thought it would go good if I followed with my thoughts as well.
If you want help in writing the actual scripts your probably best asking advice for the code in the client-side/server-side scripting forums that we've made mention.
Hope that helps, cheers.
Thanks guys




Well,
Server-side validation is a must. Absence of it is a huuge security vulnerability.
JavaScript validation is not required for security but is good for user-friendliness and to save some little bandwidth.
Bookmarks