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>
Get the submitted as an array
  $MyArray = array();
  if (isset($_POST['MyArrayName']))
    $MyArray = $_POST['MyArrayName'];
Get the values as a comma separated string
  $MyString = "";
  if (isset($_POST['MyArrayName']))
    $MyString = implode(",", $_POST['MyArrayName']);

Styling Checkboxes

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

Greyed out, non-editable

  <input type="checkbox" name"MyCheckbox" value="1" disabled/>

Just non-editable

  <input type="checkbox" name"MyCheckbox" value="1" onclick="return false;"/>
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. Required fields are marked *