Forum Moderators: coopster
Page One:
<input type="checkbox" name="choice[]" value="Person1">Person1
<input type="checkbox" name="choice[]" value="Person2">Person2
<input type="checkbox" name="choice[]" value="Person3">Person3
<input type="checkbox" name="choice[]" value="Person4">Person4
<input type="checkbox" name="choice[]" value="Person5">Person5
Page Two: (print the people and pass them to page three)
<?php
foreach($HTTP_POST_VARS['choice'] as $value) {
print ("<center>$value</center>\n");
}
?>
<?php
$choice = $_POST['choice'];
$nr_choices = count($_POST['choice']);
for ($i=0; $i < $nr_choices; $i++) {?>
<input type="hidden" name="choice[]" value="<? echo $_POST['choice'][$i]
;?>">
<? }
?>
Page Three: (Just display the values checked from Page One - they will be inserted to database later)
<?php
$username = $_POST['username'];
$choice = $HTTP_POST_VARS['choice'];
foreach($HTTP_POST_VARS['choice'] as $value) {
print ("<center>$value</center>\n");
}
?>
Anyone see what I did wrong on this. My values are passed from page one to page two and displayed. Getting the values to page three is the problem...Thanks.
$html = "<form ....>";
foreach($_POST[choice] as $key => $value)
{
$html .= $value;
$html .= "<input type=hidden name='choice[".$key."]' value='".$value."'>";
}
$html .= "<input type=submit...></form>";
echo $html;
Again, i believe this will accomplish the same thing, with alot less coding.
<form name = "AlumniResults" method = "post" action = "castvote.php" onSubmit="return check_id()">
<center><strong>You have chosen the following candidates:</strong></center>
<br>
<?php
foreach($HTTP_POST_VARS['choice'] as $value) {
print ("<center>$value</center>\n");
}
?>
<?php
$choice = $_POST['choice'];
$nr_choices = count($_POST['choice']);
for ($i=0; $i < $nr_choices; $i++) {?>
<input type="hidden" name="choice[]" value="<? echo $_POST['choice'][$i]
;?>">
<? }
?>
<!-- Create the Submit button and Back button -->
<center>
<input type="submit" name="vote" value="Submit Your Vote!">
<input type="button" value="Back" onClick="history.go(-1);return true;">
</center>
</form>
Choice[] is the name of the array on page one. Any ideas how to post this to page 3?
<?php
$choice = $HTTP_POST_VARS['choice'];
foreach($HTTP_POST_VARS['choice'] as $value) {
print ("<center>$value</center>\n");
}
?>
To be honest, I was just trying out different ways. I'm really struggling with getting page one's checkbox array values all the way through to page 3.
print '<pre>';
print_r($_POST);
print '</pre>';
exit;