Re: best way to handle required form fields
| From: | Rudi Starcevic | Date: | Wed, 14 May 2003 01:01:00 +0000 |
| Subject: | Re: best way to handle required form fields | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-147521@lists.php.net to get a copy of this message | ||
For easy form validation, including the red highlighting, maybe check out the qForms library - it's free and very powerful.
www.pengoworks.com
Cheers
Rudi.
Dan Anderson wrote:
You could do a check with Javascript to make sure the required fields were filled out and had a valid value to them. Since PHP is completely server side, you would have to check after the page had been submitted. Let's say you have a text field named "foo", ie. <INPUT TYPE=TEXT NAME="foo"> You could use: <?php if ($_POST['foo']) { do_something(); } else { error(); } ?> This is because like many programming languages 0 is false and everything else is true. Form values that are not submitted are equal to NULL -- i.e. false. You could use as many OR statements as necessary to check that everything was submitted. -Dan On Tue, 2003-05-13 at 20:20, daniel@electroteque.org wrote:hi there i was wondering what would be the most ideal way to handle required form fields say if they were empty and are required , should i do a check and send an error and return to the page with the required fields in red or would a javascript alert box (ugly) be ok ? reason being my prefered way would be sending an error although with my previous issue with custom error handlers might be tedious :|