RE: [PHP] here's a tricky one (well for me)
| From: | Boget, Chris | Date: | Tue, 06 Mar 2001 14:38:20 +0000 |
| Subject: | RE: [PHP] here's a tricky one (well for me) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-42754@lists.php.net to get a copy of this message | ||
> I am trying to let a user build a form, so on the first page they
> decide on the number of fields , when they submit that number
> it names them field1 2 3 etc,now I then want them to name the
> fields but the problem is because the number of fields varies how
> do I pass all the variables onto the next page if one time it could
> be 2 next time it could be 10
On the first page, the field name that specifies the number of fields
is "number_of_fields".
On the second page that takes that value and works with it, you can
do something like this:
for( $i = 1; $i <= $number_of_fields; $i++ ) {
$fieldName = "field$i";
echo "<input type=text name=\"$fieldName\"
value=\"${$fieldName}\"><br>\n";
}echo "<input type=hidden name=\"number_of_fields\"
value=\"$number_of_fields\">\n";
When processing your form to get the values, do essentially the same
thing:
for( $i = 1; $i <= $number_of_fields; $i++ ) {
$fieldName = "field$i";
echo "The value entered for field $i is ${$fieldName}<br>\n";
}
Through all your forms, just work with "$number_of_fields".
Chris