vendredi 17 novembre 2017

How to add values/names of checkbox to a variable on form submit?

I have a set of checkboxes in a form that has a submit button.

...
<form name="form" method="POST">
    <input type="checkbox" name="3" value="3">
    <input type="checkbox" name="7" value="7">
    <input type="checkbox" name="5" value="5">
    <input type="checkbox" name="12" value="12">
    <input type="submit" name="submit-form">
</form>
...
<?php 
if (isset($_REQUEST['submit-form'])) {
    ...
}
?>
...

When the form is submitted, I want to add the values or names of the checked checkboxes to a PHP variable, separated by commas, as a string.

Any help with the code that I should put in the if brackets would be much appreciated.

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire