Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validating fields on a form

Status
Not open for further replies.

ChrisRChamberlain

Programmer
Mar 23, 2000
3,392
GB
Hi all

Using a form on a html page to send data to an email php script.

The php script will trap an empty email address and posts a error dialog which forces the user to return to the html page.

Would prefer to trap empty required fields on the html page rather than in the php script.

How to do?

TIA

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.com
PDFcommandertm.co.uk


 
You will need to use Javascript.
Which means that the validation won't work for people with javascript turned off.

Validating with the PHP script would be preferable to me as this will work no matter how the users browser is set up.

Maybe you can do a combination of the two methods?

- Web design and ranting
- Day of Defeat gaming community
"I'm making time
 
Like Foamcow says, do it with Javascript - Googling for javascript validator script will turn up plenty of options.

However, you'll need to do the same validation in your php script too, because some people have JS switched off, and others might (conceivably) try to break your system by viewing source on your form and constructing their own to send you invalid data.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
It depends what sort of and how much data you are collecting, how you think the form should work for your users and consequently how you set it up.

Personally I much prefer doing the validation with PHP once the user submits. This avoids the problem of users having Javascript disabled. Sure you can do it both ways but what's the point of validating the same data in the same way twice?

Ont he other hand... from a usability point of view it may sometimes be better to tell the user IMMEDIATELY if they have not filled something in correctly.

For instance, if they enter an invalid ZIP/Postal code it might be nice to tell them the MOMENT that they leave the Zip/Post code field. This is especially true if you have a large or multi part form.
This can be done with javascript as it works on the client side and you can trap things before the user hits submit.

At the end of the day, you need to look at the particular cirumstances and weigh up the pros and cons of each method.


- Web design and ranting
- Day of Defeat gaming community
"I'm making time
 
I usually use both client-side and server-side scripting. While not a major drain by any means, let's say you had 10 file input boxes.

The form might take a few seconds to submit. The last thing you want to do is make the user wait, just to find out he has to go back and re-enter some data.

What I do is do preliminary JavaScript validation, then duplicate (same tests) the validation on the server side using PHP.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top