note 19947 deleted from language.types.array by curt
| From: | curt@php.net | Date: | Tue, 06 Jul 2004 02:13:27 +0000 |
| Subject: | note 19947 deleted from language.types.array by curt | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-72644@lists.php.net to get a copy of this message | ||
Note Submitter: sssolomon@hotmail.com
----
For forms I use "${$foo}" thing:
if ($action=="")
{
echo "<form method=\"post\" action=\"form.php\">";
$amount=3; //(or input on another form)
For ($loopVar=0; $loopVar<$amount; $loopVar++)
{
printf ("Input number %s <input type=\"text\" name=\"%s\">",
($loopVar+1),$loopVar);
}
echo "<input type=\"hidden\" name=\"action\"
value=\"submit\"><input type=\"hidden\" name=\"amount\"
value=\"$amount\"><input type=\"submit\" name=\"submit\"
value=\"submit\"></form>";
}elseif ($action=="submit")
{
for ($loopVar=0; $loopVar<$amount; $loopVar++)
{
$input[$loopVar]=${$loopVar};
}
}
I like this way best. You can also have multiple inputs. Just for the second "printf()"
use:
printf ("Input number %s <input type=\"text\" name=\"%s\">",
($loopVar+1),($loopVar+1)*1000000);
and for the loop change ${$loopVar} to ${$((loopVar/1000000)-1)};
That is so that you don't have 2 fields the same "name=" unless the person asks to
input more than 1 million numbers...