mardi 5 juin 2018

Array of checkbox values in PHP

I have a HTML form with multiple checkbox selection. They are defined as:

<label class="container">Afghanistan
        <input type="checkbox" id="Afghanistan" name="country[]" value="Afghanistan" checked="checked">
        <span class="checkmark"></span>
    </label>
    <label class="container">Armenia
        <input type="checkbox" id="Armenia" name="country[]" value="Armenia" checked="checked">
        <span class="checkmark"></span>
    </label>
...

After submitting, I call a PHP file where I want to store their values in an array.

for($i=0;$i<sizeof($_POST["country[]"]);$i++){
    $country[i] = htmlspecialchars($_POST["country[i]"]);
  }

But this code doesn't work. Can anyone help me to solve it?




Aucun commentaire:

Enregistrer un commentaire