0

THIS IS NOT A DUPLICATE

I follow the exact steps that the my question is a suppose "duplicate" of and I get a completely different result.

I have a form that has 5 checkboxes. When I submit the form and I print the value of the checkbox array I get the word on for each checkbox that was selected instead of the value.

Here is my HTML

<div class="checkbox">
  <label style="width:auto !important;">
    <input type="checkbox" name="additional[]" value="contact">
    Contact Form
  </label>
</div>
<div class="checkbox">
  <label style="width:auto !important;">
    <input type="checkbox" name="additional[]" value="google">
    Google Map
  </label>
</div>
<div class="checkbox">
  <label style="width:auto !important;">
    <input type="checkbox" name="additional[]" value="sub">
    Subscribe Feature
  </label>
</div>
<div class="checkbox">
  <label style="width:auto !important;">
    <input type="checkbox" name="additional[]" value="caro">
    Image carousel
  </label>
</div>
<div class="checkbox">
  <label style="width:auto !important;">
    <input type="checkbox" name="additional[]" value="bar">
    Search Bar
  </label>
</div>

This is my PHP to get the value of additional[] when the form is submitted,

$add = $_POST["additional"];

I then loop through them to see each checkbox that was selected,

$addThings = "";

foreach($add as $value) {
$addThings.= " $value ";
}
echo $addThings;

The output is this,

on on on

It displays an on for each checkbox that has been selected.

How can I get it to display the actual value?

Gary Holiday
  • 3,297
  • 3
  • 31
  • 72
  • are you sure you're on the right form? your checkbox values has `value="bar"`, the default value is `on` when this is omitted. no one would be able to reproduce this based on the question above – Kevin Mar 23 '15 at 02:49
  • The issue is not reproduced – Tamil Selvan C Mar 23 '15 at 02:49
  • This is not a duplicate. The suppose duplicate answer does not help me in this situation. Did you even read my question? – Gary Holiday Mar 23 '15 at 02:54
  • Your form is a duplicate. My guess is that, you're not showing us full code and that is why @TamilSelvan said they were unable to reproduce. I on the other hand, was able to successfully test this using proper form syntax, using a POST method. If your form does not contain that, and you're relying on another method to achieve this, such as JS/Ajax; then add it to your question. As it stands, it's still a duplicate. If you are using form tags and a POST method isn't included; forms default to GET. – Funk Forty Niner Mar 23 '15 at 12:52
  • http://php.net/manual/en/tutorial.forms.php – Funk Forty Niner Mar 23 '15 at 12:54

0 Answers0