You are here: Re: Array doesn't pass. « PHP Programming Language « IT news, forums, messages
Re: Array doesn't pass.

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]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация