Skip to content Skip to sidebar Skip to footer

Retrieving Values From A Checkbox

I use a php checkbox and I want to retrieve marked values. My checkbox code :

Solution 1:

You have to change the name attribute to cours[] and then php will treat it as an array.

Read up at http://docs.php.net/faq.html

Solution 2:

You may use some thing like this..

<labelfor="cours">Je suis intéressé par un ou plusieurs cours :</label><br><br><inputtype="checkbox"name="cours[0]"value="individuel">Individuel<br><inputtype="checkbox"name="cours[1]"value="semiprive">Semi-privé<br><inputtype="checkbox"name="cours[2]"value="minigroupe">Mini-groupe<br><inputtype="checkbox"name="cours[3]"value="intensif">Intensif<br><inputtype="checkbox"name="cours[4]"value="entreprise">Entreprises<br><inputtype="checkbox"name="cours[5]"value="distance">A distance<br><inputtype="checkbox"name="cours[6]"value="telephone">Par téléphone<br><inputtype="checkbox"name="cours[7]"value="coaching">Coaching<br><inputtype="checkbox"name="cours[8]"value="soutien">Soutien scolaire<br><inputtype="checkbox"name="cours[9]"value="diplome">Diplômes officiels<br>

Solution 3:

Print all checkbox value.

<formaction="print.php"method="post"><inputtype="checkbox"name="val_list[]"value="value 1"><inputtype="checkbox"name="val_list[]"value="value 2"><inputtype="checkbox"name="val_list[]"value="value 3"><inputtype="checkbox"name="val_list[]"value="value 4"><inputtype="checkbox"name="val_list[]"value="value 5"><inputtype="submit" /></form><?phpif(!empty($_POST['val_list']))
         {
        foreach($_POST['val_list'] as$data)
             {
                echo$data; 
             }
         }
   ?>

Post a Comment for "Retrieving Values From A Checkbox"