RE: [PHP] Required fields in a form?

From: Date: Fri, 13 Oct 2000 23:42:46 +0000
Subject: RE: [PHP] Required fields in a form?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20126@lists.php.net to get a copy of this message
This doesn't address your question directly but one simpler way to require fields in a form is to, in your form processor, do something like this : <? if (!$fname || !$lname) { echo 'give us your name please! '; } else { // all required fields are filled, process form. > -----Original Message----- > From: Erica Douglass [mailto:erica@cobalt.com] > Sent: Friday, October 13, 2000 4:34 PM > To: php-general@lists.php.net > Subject: [PHP] Required fields in a form? > > > I am trying to build a form that checks if certain required fields are > filled out. Not all fields are required, hence my problems. > > The form calls from a table called "form_fields" that, very simplified, > looks like this: > > field_name | required > __________________________ > fname | yes > lname | yes > wphone | no > > The form is pulled from the same table. Form value names are evaluated as > field_name from the database. Hence, a text field asking for the user's > first name looks like this when initially called from the database: <input > type="text" name="fname" size="30" value=""> > > > > The code I am using to check for required fields looks like this: > > # check to make sure required fields are filled in > $query = "select field_name from form_fields where required=\"yes\""; > $result = mysql_query ($query) or die ("The server is down. Here's what > MySQL said: " . mysql_error()); > $required_fields = mysql_fetch_array($result); > while(list($key,$val) = each($required_fields)) { > if ($HTTP_POST_VARS[$key] == "") { > echo "$key is blank!"; > } > else { > echo "$key is not blank!"; > }; > }; > > I am using the echo statements as placeholders for now. > > This code, when put to use, gives back the following output (regardless of > whether the form fields are actually blank or not): > > 0 is blank!field_name is blank! > > What on earth am I doing wrong? I have a feeling that I have the right > idea, but that my code is off. Please help! :) > > Erica > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#20126) next »