Checkbox Example

<label>Venue Does Weddings?</label><br />
<input type="checkbox" name="my_checkbox_name" value="Yes" />

<input type="checkbox" name="my_checkbox_name" value="Yes" />My label<br>

<!-- To show the checkbox already checked -->
<input type="checkbox" name="my_checkbox_name" value="Yes" checked />
<input type="checkbox" name="my_checkbox_name" value="Yes" checked="checked" />
Handling in PHP
if(isset($_POST['my_checkbox_name']) && $_POST['my_checkbox_name'] == 'Yes')
    echo "Checked";
    echo "Not checked";

Checkboxes with an array of values

  <label>My array checkboxes</label>
  <input type="checkbox" name="MyArrayName[]" value="MyValue1" />My Value 1<br>
  <input type="checkbox" name="MyArrayName[]" value="MyValue2" />My Value 2<br>
  <input type="checkbox" name="MyArrayName[]" value="MyValue3" />My Value 3<br>

To get the values in PHP as say a comma separated string:

  echo implode(",", $_POST['MyArrayName']);

Styling Checkboxes

We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.