I have this idea of a page i want to create but i really don't know how i would implement it . I want to create a page with some pictures and below each picture there would be a check box , i want people to be able to select the check box click next and when they are at the next page the item they checked would automatically be in a dropdown list .

Dani AI

Generated

You want image tiles with checkboxes that carry the visitor's picks to the next page and show them in a list or a dropdown. Since you settled on PHP ( and ) that is straightforward and reliable. is right to call out GET/POST; use POST for this kind of selection unless you want the choices visible in the URL. is also correct that JavaScript can do the whole flow client-side — below shows a small, safe server-side pattern and notes alternatives.

Use checkbox inputs named as an array (note the trailing brackets) so PHP receives all checked values. Prefer stable IDs as values (so users can’t easily spoof names) and unique id attributes for each input/label pair:

<form method="post" action="review.php">
  <label for="item-1">
    <img src="img1.jpg" alt="Item 1">
    <input type="checkbox" id="item-1" name="items[]" value="1">
  </label>
  <button type="submit">Next</button>
</form>

On the server, validate and escape before output. Map submitted IDs back to server-side labels (prevents tampering), check the array is present, and escape output with htmlspecialchars when rendering a <select>:

<?php
$selected = isset($_POST['items']) ? $_POST['items'] : array();
$labels = array('1'=>'Onions','2'=>'Mushrooms','3'=>'Tomatoes');

if (empty($selected)) {
  echo "No items selected.";
} else {
  echo '<select name="chosen">';
  foreach ($selected as $id) {
    if (!isset($labels[$id])) continue;
    $label = htmlspecialchars($labels[$id], ENT_QUOTES, 'UTF-8');
    echo "<option value=\"$id\">$label</option>";
  }
  echo '</select>';
}
?>

Troubleshooting tips: use name="items[]" (common gotcha), don’t reuse id values, prefer POST for privacy, use sessions if the selection must persist across many steps, and escape all output to avoid XSS. For reference: MDN on checkboxes (input type=checkbox) and PHP’s htmlspecialchars docs (php.net).

Recommended Answers

All 6 Replies

Rather I want to create a page with some pictures and below each picture there would be a check box , i want people to be able to select the check box click next and when they are at the next page the name of the item they checked would automatically be displayed . something similar to what happens here http://www.htmlcodetutorial.com/forms/_INPUT_TYPE_CHECKBOX.html when you select either onions or mushrooms and click submit

what is your server scripting language. php, perl-cgi, asp.net, java or any other.

Hi urtevedi , PHP is what i would like to use for this . I would be very grateful if you could help out.

What did you try yet?
In PHP, you can access GET variables (if you used method=get in your form) in the superglobal $_GET, and the POST variables (if method=post) in $_POST. For example, if you have a checkbox with name=someCheckbox, $_GET (or post, but get is probably better in this case, as you're not putting anything in a database) will be 'on' or '' (checked or not). Hope that helps.

your first html page

<form name=frm id=frm method=post action=showselected.php>
<img src='imga.jpg' ><checkbox name=chk id=chk value='imga.jpg'><br>
<img src='imgb.jpg' ><checkbox name=chk id=chk value='imgb.jpg'><br>
<img src='imgc.jpg' ><checkbox name=chk id=chk value='imgc.jpg'><br>
<img src='imgd.jpg' ><checkbox name=chk id=chk value='imgd.jpg'><br>
<img src='imge.jpg' ><checkbox name=chk id=chk value='imge.jpg'><br>

<input type=submit value=submit>
</form>

showselected.php

<?php
   $selcount=count($_POST['chk']);
   echo "YOu have selected following $selcount images:<br>";
   for($i=0;$i<$selcount;$i++)
   {
       echo $_POST['chk'][$i]."<br>";
   }
?>

I think it can be easy using javaScript:-/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.