Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to post the array values from one form to another. Here is the code for the sender:
<?phpprint "<h1>Checkbox Questions: </h1>
";for($x = 0; $x < $checkbox; $x++)
{
print "Text: " . '<input type = "text" size = 60 name = "$checkbox_q_" . [$x]>' . " " . "Options: "
. '<input type = "text" size = 5 name = "$checkbox_o_" . [$x]>' . " " . "Points: " .
'<input type = "text" size = 5 name = "$checkbox_p_" . [$x]>' . "
";
}
?>
<body><form action= "finalize_quiz.php" method = "post">
<input type = submit value = "Finalize Quiz...">
</form>
</body></html>So with the code above, a certain amount of text forms will be printed, and for each iteration the values will be written to $checkbox_q_[$x]. So I should be able to read the values as arrays (ie. $checkbox_q_[4]).
And here is the code for the reciever, just a very simple test that should print the very first element of whatever was entered in the previous form. This file is finalize_quiz.php:
<?php
$checkbox_text = $_POST[checkbox_q_[]];
print checkbox_q_[0];
?>And it doesn't work. Any Clues?
Thanks,
Igor

1. You can't "print" an array in that manner.
2. I don't think the way you coded your input boxes will work correctly. What does the HTML look like when processed.
3. It looks like you are trying to make the names of the checkboxes as array indexes (i.e. $checkbox_q_[0], checkbox_q_[1], etc.). You can't do that. HTML doesn't recognize arrays - and I don't know that you can even use those character in a field name.
Here is my suggestion. have the field names go like this: checkbox0, checkbox1, checkbox2, etc. Then on the page that processes the form, put the values into an array if you need to. There is one problem however, I don't think that checkboxes and their values are passed if the checkbox is not checked. So you will need to put some logic into the processing page such as:
for($x = 0; $x < length; $x++)
{ // you need to define length somehowif ($_POST["checkbox_"+$x]) {
checkbox[$x] = $_POST["checkbox_"+$x];
} else {
checkbox[$x] = "";
}}
Michael J

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |