Jump to content

[SOLVED] Compare Form Elements


PHPNewbie55

Recommended Posts

I would like to add a "compare" option to one of my pages.

I have 28 items listed per page...

Next to each item I would like to put a check box and a button at the bottom that when clicked would take you to a page that displays all the items that were checked on the form....

 

The problem I have -- or what I don't understand is how to use the info from each checked box to pull those products from the MySQL Database..

 

I have created several forms that do similar functions...  but I always know what form elements are named and what the value is going to be...

 

Example Form:

<form id="form1" name="form1" method="post" action="compare.php">
  <input type="checkbox" name="checkbox1" id="checkbox1" />
  <input type="checkbox" name="checkbox2" id="checkbox2" />
  <input type="checkbox" name="checkbox3" id="checkbox3" />
  <input type="checkbox" name="checkbox4" id="checkbox4" />
  <input type="checkbox" name="checkbox5" id="checkbox5" />
<input name="Submit" type="button" value="Compare Items" />
</form>

 

So with the form above how would I extract the checked box info..??

 

Usually I know what the values are... and how many items to expect on the submit form....

But in this case I don't know how many items will be selected or what the values will be..

$????? = ($_POST["?????????"]);

 

So how would I get that information on the submit form.....???

I hope this makes sense...  any help would be appreciated.......

Link to comment
https://forums.phpfreaks.com/topic/149178-solved-compare-form-elements/
Share on other sites

Heres some options

 

#1

<input type="checkbox" name="checkbox1" id="checkbox1" />
ifisset($_POST['checkbox1'])
{
echo "checkbox1 was checked";
}

#2

<input type="checkbox" name="checkbox1" id="checkbox1" value="test" />
$data = $_POST['checkbox1']; //=test

 

#3

  <input type="checkbox" name="checkbox[1]" id="checkbox1" value="123"/>
  <input type="checkbox" name="checkbox[2]" id="checkbox2" value="456"/>
  <input type="checkbox" name="checkbox[3]" id="checkbox3" value="789"/>
  <input type="checkbox" name="checkbox[4]" id="checkbox4" value="abc"/>
  <input type="checkbox" name="checkbox[5]" id="checkbox5" value="def"/>

foreach($_POST['checkbox'] as $K => $CB)
{
echo "checkbox $K was checked with the value '$CB'<br>";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.