Re: Dynamic Arrays
| From: | Analysis & Solutions | Date: | Thu, 13 Jun 2002 03:42:38 +0000 |
| Subject: | Re: Dynamic Arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-101880@lists.php.net to get a copy of this message | ||
Hi Folks:
I was going to propose something similar. Allow me to tweak:
> <form ....>
> *<input type="text" name="my_array[foo]" value="">
> *<input type="text" name="my_array[bar]" value="">
> <input type="text" name="my_array[blankable]" value="">
> </form>
>
> on you script page
> <?
> # $mand = array("foo", "bar");
$mand = array('foo', 'bar');
> # $cnt = count($mand);
> # for ($i = 0; $i < $cnt; $i++)
> # if (!in_array($mand[$i], $my_array))
> # echo "Error: You missed a required field -
> ".$mand[$i]."<br>\n";
$Prob = array();
while ( list(,$Key) = each($mand) ) {
if ( empty($_POST[$Key]) ) {
$Prob[] = "$Key is a required field";
}
}
if ( !empty($Prob) ) {
echo "<ul>\n";
while ( list(,$Val) = each($Prob) ) {
echo " <li>$Val.</li>\n";
}
echo "</ul>\n";
} else {
# Go ahead. Fields are filled in.
}
> ?>
Enjoy,
--Dan
--
PHP classes that make web design easier
SQL Solution | Layout Solution | Form Solution
sqlsolution.info | layoutsolution.info | formsolution.info
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409