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 />
//or
<input type="checkbox" name="my_checkbox_name" value="Yes" checked="checked" />
Handling in PHP
<?php
if(isset($_POST['my_checkbox_name']) && $_POST['my_checkbox_name'] == 'Yes')
{
    echo "Checked";
}
else
{
    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

https://www.w3schools.com/howto/howto_css_custom_checkbox.asp

Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published.