[thelist] field checking in PHP

Martin Kuplens-Ewart martin at takingitglobal.org
Tue Dec 18 10:34:20 CST 2001


The code would be half as long if you name your form fields
MyForm[FieldName]... That way the submitted values get assigned to the
MyForm array... Which means that we can do the following:

IF NOT DISPLAYING THE EMPTY FIELDS:

foreach($MyForm as $value)
{
	$checkint++;
}
if($checkint > 0 && $checkint < 13)
{
	echo ("You must complete all or none of the fields!");
	$angry = 1;
}


IF YOU WANT TO HIGHLIGHT THE EMPTY FIELDS...

...and you'll be displaying the form in the page again for the user to
make corrections:
Inside your form tag...

--------code fragment--------

<?if($angry && !$MyForm[FieldName1]){echo("<font color="red"> *</font>
");}?>My Field Label: <input type="text"
name="MyForm[FieldName1]"<?if($MyForm[FieldName1]){echo("
value=\"".$FieldName1."\");}?> />

-----------------------------


Make sense?

-m






More information about the thelist mailing list