Working with checkboxes and php

Free Scripts :: PHP :: PHP and Forms :: Working with checkboxes and php

Author: Salman Javaid

Website: http://www.salman.be

  • How to process checkboxes with php.
  • How to get posted checkbox values with php.
  • Working with php and checkboxes.

This script process posted checkbox values sent from a form. We have 2 php pages. At Forms.php we have a form with checkboxes and a submit button. Once we click submit button after selecting few checkboxes, the page submits values to Save.php. Then we get all selected checkbox values with the help of for loop.

Form.php

<form method="post" action="Save.php">
    <input type="checkbox" name="country[]" value="Belgium" /> Belgium
    <input type="checkbox" name="country[]" value="France" /> France
    <input type="checkbox" name="country[]" value="Germany" /> Germany
    <input type="checkbox" name="country[]" value="Holland" /> Holland
    <input type="checkbox" name="country[]" value="Greece" /> Greece
    <input type="Submit" value="Submit" />
</form>

Save.php

if(!empty($_POST['country'])){

        for ($i=0; $i < count($_POST['country']);$i++) {

               echo $_POST['country'][$i] . ", ";

        }

}

Output:

Belgium, Germany, Greece,

Comments

No comments. Be the first one.

Leave a comment

Full Name*
Comments*
Security Code*

Our Partners

Getty Icons  Salman Creations
Free High Quality Images  Learn Free Languages 
Opal Hosting  R-Tech Solutions
  • Submit a Script

    Click here to submit your script.