{"id":732,"date":"2013-01-07T18:02:31","date_gmt":"2013-01-07T18:02:31","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=732"},"modified":"2025-08-03T19:56:46","modified_gmt":"2025-08-03T18:56:46","slug":"checkbox","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/html\/forms-html\/checkbox\/checkbox","title":{"rendered":"Checkbox"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">Checkbox Example<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;label&gt;Venue Does Weddings?&lt;\/label&gt;&lt;br \/&gt;\n&lt;input type=\"checkbox\" name=\"my_checkbox_name\" value=\"Yes\" \/&gt;\n\n&lt;input type=\"checkbox\" name=\"my_checkbox_name\" value=\"Yes\" \/&gt;My label&lt;br&gt;\n\n&lt;!-- To show the checkbox already checked --&gt;\n&lt;input type=\"checkbox\" name=\"my_checkbox_name\" value=\"Yes\" checked \/&gt;\n\/\/or\n&lt;input type=\"checkbox\" name=\"my_checkbox_name\" value=\"Yes\" checked=\"checked\" \/&gt;\n<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Handling in PHP<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nif(isset($_POST&#91;'my_checkbox_name']) &amp;&amp; $_POST&#91;'my_checkbox_name'] == 'Yes')\n{\n    echo \"Checked\";\n}\nelse\n{\n    echo \"Not checked\";\n}   \n \n?&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Checkboxes with an array of values<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  &lt;label&gt;My array checkboxes&lt;\/label&gt;\n  &lt;input type=\"checkbox\" name=\"MyArrayName&#91;]\" value=\"MyValue1\" \/&gt;My Value 1&lt;br&gt;\n  &lt;input type=\"checkbox\" name=\"MyArrayName&#91;]\" value=\"MyValue2\" \/&gt;My Value 2&lt;br&gt;\n  &lt;input type=\"checkbox\" name=\"MyArrayName&#91;]\" value=\"MyValue3\" \/&gt;My Value 3&lt;br&gt;<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Get the submitted as an array<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyArray = array();\n  if (isset($_POST&#91;'MyArrayName']))\n    $MyArray = $_POST&#91;'MyArrayName'];<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Get the values as a comma separated string<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  $MyString = \"\";\n  if (isset($_POST&#91;'MyArrayName']))\n    $MyString = implode(\",\", $_POST&#91;'MyArrayName']);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Styling Checkboxes<\/h4>\n\n\n\n<p><a href=\"https:\/\/www.w3schools.com\/howto\/howto_css_custom_checkbox.asp\">https:\/\/www.w3schools.com\/howto\/howto_css_custom_checkbox.asp<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Greyed out, non-editable<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  &lt;input type=\"checkbox\" name\"MyCheckbox\" value=\"1\" disabled\/&gt;<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Just non-editable<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>  &lt;input type=\"checkbox\" name\"MyCheckbox\" value=\"1\" onclick=\"return false;\"\/&gt;<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Checkbox Example Handling in PHP Checkboxes with an array of values Get the submitted as an array Get the values as a comma separated string Styling Checkboxes https:\/\/www.w3schools.com\/howto\/howto_css_custom_checkbox.asp Greyed out, non-editable Just non-editable<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[384],"tags":[],"class_list":["post-732","post","type-post","status-publish","format-standard","hentry","category-checkbox"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/732","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=732"}],"version-history":[{"count":13,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/732\/revisions"}],"predecessor-version":[{"id":4414,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/732\/revisions\/4414"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}