Web Hosting Talk







View Full Version : Validate form data with php


hostseeker
03-11-2002, 02:01 PM
How do you validate form data using php? I currently use javascript but users can turn that off. For example I want to make sure a user completes a field (does not leave it blank) before the form is submitted to a cgi script for action.

Any ideas (or code snippets) are appreciated!

kunal
03-11-2002, 02:38 PM
why not edit your cgi script to validate it??

hostseeker
03-11-2002, 02:46 PM
Originally posted by kunal
why not edit your cgi script to validate it??

That is something I haven't thought of but I don't know how to do it and I think that using PHP to validate the form itself before passing the data off to the cgi script would be easier. The form passes data to a cgi script that searches a database. Also I have other forms that I would like to validate the data for and they use different scripts so I guess that's why I am searching for some general code to use with forms to make sure that the user completes the fields.

Ideally I could specify a minimum number of characters, but if I can't do that, I would like to make sure they are not left blank.

Thanks for your reply!