View Full Version : Submit form that has dynamically generated checkboxes

12-02-2007, 05:27 AM
I'm not well-versed in PHP but managed to dynamically generated a page/list of items, and their descriptions, images.... including a checkbox before each items. That page - page 1 - is ok.

<form name="compareForm" method="post" action="page2.php">
<input type="checkbox" value="<?php print $id ?>" name="compare[]" />
<a href="javascript:document.compareForm.submit();">Compare</a>
[end loop]

Viewing source shows that the Value of the checkboxes are generated correctly - which are the Item Ids - 1, 2, 3...

However, if I check some checkboxes and submit the form, the values don't seem to be passed to page 2, which has the following codes:

$compare = $_POST["compare"];
foreach ($compare as $value) {
print $value."<br />";}

Things that I tried:
- Changed value="<?php print $id ?>" to hard-coded value="123": not work
- Use only one Submit button at the end of the form instead of the Submit links under each item: not work

Did I miss anything? or can we pass dynamically generated checkbox values?

Thanks for the inputs!

10-30-2008, 05:56 PM
I am having the same issue.
my dynamically created checkbox is not being posted.
looks like nobody knows about this.

11-04-2008, 05:07 AM
I have the same problem!
I have javascript on my code but the javascript works fine, so I can't figure out the php either.

11-04-2008, 05:58 AM
It works fine. Testing example:

$compare = $_POST["compare"];
echo '<h2>Checkbox values:</h2>';
foreach ($compare as $value)
echo $value."<br />";
<form name="input" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
echo '<input type="checkbox" value="test'.$i.'" name="compare[]" />';
<input type="submit" value="Submit" name="submit">

Checkbox/es needs to be checked to see the values.