Reply to Re: Array doesn't pass.

Your name:

Reply:


Posted by Daz on 11/04/06 16:55

T. Wintershoven wrote:
> Can anyone help me solve this problem.

Another solution might be this:

if (!isSet($_POST['submit']))
{
ShowForm();
}
else
{
HandleForm();
}
// Declare the question array in the global scope.
$question=array();
$question[0]="100";
$question[1]="125";
$question[2]="150";
$question[3]="175";
$question[4]="200";

function ShowForm() {
global $question;

echo"<form name='form1' method='post'
action='".$_SERVER['PHP_SELF']."'>";

for($i=0; $i<5; $i++) {
// This time we are making a unique name for the checkbox
// (i.e question_1, question_2 etc...).
echo "<input type='checkbox' name=$question_$i> This is the "
."question with ID ". $question[$i]."<br/>";
}
echo "<BR><input type='submit' name='submit' value='Show
choice'>";
echo"</form>";

}

function HandleForm() {
global $question;

for($i=0; $i<5; $i++) {
// Create the name for the checkbox we can't to check.
$question_name = "question_".$i;
// This may not be a legit method, but by adding '2' dollar
signs to the beginning
// of the variable, the variable name is correctly parsed as it
should be.
if(isset($_POST[$$question_name])) {
echo "Question ".$_POST[$question[$i]]." was "
."ticked.<br/>";
}
}
}

I haven't tested it, but I hope you get the idea.

[Back to original 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

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация