|
Posted by Kimmo Laine on 11/06/06 09:04
"T. Wintershoven" <twintershoven@casema.nl> wrote in message
news:s7udnRhqqd0iMNHYRVnygQ@casema.nl...
> Hello all,
>
> I have a form with some checkboxes.
> The names of these checkboxes come from an array.
> When i click the submit button the resultcode doesn't recognize the names
> when i want to check wether or not some checkboxes are ticked.
>
> Assume that i tick checkboxes 100, 150 and 200
>
> Below is some code i've used.(between the ****** lines)
> ************************************************
> if (!isSet($_POST['submit']))
> {
> ShowForm();
> }
> else
> {
> HandleForm();
> }
>
> function ShowForm()
> {
> //normally, these values come out of a database
> $question=array();
> $question[0]="100";
> $question[1]="125";
> $question[2]="150";
> $question[3]="175";
> $question[4]="200";
>
> echo"<form name='form1' method='post' action='".$_SERVER['PHP_SELF']."'>";
>
> for($i=0; $i<5; $i++)
> {
> echo "<input type='checkbox' name=$question[$i]> This is the
^^^^^^^^^^^^^
"$question[$i]" will print literally 'array[1]', not '100' like you
intended. If you want it to work, you gotta denote the array reference with
curly braces:
echo "<input type='checkbox' name='{$question[$i]}'> This is the...."
Now you'll get '100', '125', etc, which gets us to the second problem:
having plain numbers as field names. Well, perhaps it's not a problem, but
it is something I wouldn't do. The only explanation I can offer for this is
"just because". I'd throw in some alphabets, just in case, name them 'q100',
'q125', etc...
> question with ID ". $question[$i]."<br/>";
> }
> echo "<BR><input type='submit' name='submit' value='Show choice'>";
> echo"</form>";
> }
>
> function HandleForm()
> {
> for($i=0; $i<5; $i++)
> {
> if(isset($_POST[$question[$i]]))
Here you reference correctly the field names 100, 125, etc.. but the reason
they are not found is the fields are actually named array[0]..., like I
explained earlier...
--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti pδivittyvδ nettisarjis
spam@outolempi.net | rot13(xvzzb@bhgbyrzcv.arg)
Navigation:
[Reply to this message]
|