have built a functional form with PHP however I have a checkbox with 5 options (more than 1 can be selected) however only 1 option is showing up in the email. HTML:
Solution 1:
If you have multiple elements with the same name then you will only be able to read one of them unless you use the array syntax []
e.g. name=service[]
then you will receive $_POST['service'] as an array containing all your services. You can use implode to convert it to a string.
$service = implode(' ' , $_POST ['service' ]);
Copy Solution 2:
Use array in name, where you named it service write there, service[].
then use multiple="multiple" tag.and in php part use this:
<?php $services =implode(',' ,mysql_real_escape_string($_post ['service' ]));
print_r($services );
?>
Copy Happy Coding!
Solution 3:
User array name instead of simple name in checkbox like this :
<label class ="radio" ><input type ="checkbox" name ="service[]" value ="Web Design" /> Web Design </label>
<label class ="radio" > <input type ="checkbox" name ="service[]" value ="Graphic Design" /> Graphic Design</label > <label class ="radio" > <input type ="checkbox" name ="service[]" value ="Brand Identity" /> Brand Identity</label > <label class ="radio" > <input type ="checkbox" name ="service[]" value ="Online Marketing" /> Online Marketing</label > <label class ="radio" > <input type ="checkbox" name ="service[]" value ="Other" /> Other</label > print_r ($_POST['service' ]);
Array
(
[0 ] => Web Design
[1 ] => Graphic Design
[2 ] => Brand Identity
[3 ] => Online Marketing
[4 ] => Other
)
Copy Solution 4:
Put name="service[]"
(Array) instead of name="service"
in your form to get the multiple selected value as array. And while retrieving you could get the value using implode
function as follows
$services = implode("," , $_POST ['service' ]);
Copy
Post a Comment for "Multiple Checkbox Options On A Php Form"