answersLogoWhite

0

with a form being POSTed to another page (or itself) $_POST['checkbox_name'] will give the value IF you use <input type="checkbox" name="checkbox_name" value="1" />

if you submit your form with method="get" then $_GET['checkbox_name'] will give the value.

there is also $_REQUEST['checkbox_name'] which is a merging of $_GET and $_POST BUT I suggest you shy away from using this method, as its easier to debug when you know where stuff is coming from

BUT checkboxes DO NOT get submitted if you dont tick them.

My personal workaround to force the value being submitted is this:-

<input type="hidden" name="checkbox_name" value="0" />

<input type="checkbox" name="checkbox_name" value="1" />

When the webpage goes through the form to collate the values, IF the checkbox is ticked, it will overwrite the 0 value with 1. IF not then 0 will be submitted.

Hope this covers everything for you.

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

What are the Error occurs when no checkbox is checked in PHP?

Suppose you have checkbox in HTML from and and you are calling that checkbox by name in php , In that case in you don't check and hit submit , You will get Undefined parameter 'name_of _checkbox' As Error.


How are checkboxes sent to PHP from HTML?

The value associated with the checkbox's name, if it is checked, is the value attribute on the corresponding HTML input element.


How do you post the data from an input type checkbox in a form to MySQL tables using PHP?

using the post command.$_POST['checkboxname'];


How do you return a value in a PHP function?

Below is a simple example of how you could return a value in a PHP function. &lt;?php function returnme($value) { return $value; } echo returnme('hello'); // outputs: hello ?&gt;


How do you retrieve results of multiple checkboxes in php?

Well that's fairly easy, as - if you done it correctly - every checkbox has a name, and if this checkbox has been ticked, the POST or GET variable will hold a value named "on", after submitting the form. A standard code to check wether it has been submitted and checked can be something like: if(isset($_POST['checkbox1']) &amp;&amp; !empty($_POST['checkbox1'])){ do something here... } that's it.


Where would one find information online on how to use the php admin?

One can use a Php admin to store information which can be easily accessed. If one uses the Php my admin one can have it to keep updated automatically.


How do you increment a number using while in php?

Example: &lt;?php $value = 10; $i = 0 if(is_int($value)) { while($i &lt; $value) { echo $i; echo '&lt;br/&gt;'; $i++; } } ?&gt;


When should globals be used in PHP?

Problem with using global variables in php is that they lose the the assigned value in a different php file. They only keep the global variable value in the php file in which they are declared. Instead of globals try and use $_SESSION or $_COOKIE to keep value intact across different php files in a project


Html pull down menu example for month day and year I would like to get an example on how to write month day and year in HTML form?

# &lt;select name="month" id="month"&gt; # &lt;option value="1" &lt;?PHP if($month==1) echo "selected";?&gt;&gt;January&lt;/option&gt; # &lt;option value="2" &lt;?PHP if($month==2) echo "selected";?&gt;&gt;February&lt;/option&gt; # &lt;option value="3" &lt;?PHP if($month==3) echo "selected";?&gt;&gt;March&lt;/option&gt; # &lt;option value="4" &lt;?PHP if($month==4) echo "selected";?&gt;&gt;April&lt;/option&gt; # &lt;option value="5" &lt;?PHP if($month==5) echo "selected";?&gt;&gt;May&lt;/option&gt; # &lt;option value="6" &lt;?PHP if($month==6) echo "selected";?&gt;&gt;June&lt;/option&gt; # &lt;option value="7" &lt;?PHP if($month==7) echo "selected";?&gt;&gt;July&lt;/option&gt; # &lt;option value="8" &lt;?PHP if($month==8) echo "selected";?&gt;&gt;August&lt;/option&gt; # &lt;option value="9" &lt;?PHP if($month==9) echo "selected";?&gt;&gt;September&lt;/option&gt; # &lt;option value="10" &lt;?PHP if($month==10) echo "selected";?&gt;&gt;October&lt;/option&gt; # &lt;option value="11" &lt;?PHP if($month==11) echo "selected";?&gt;&gt;November&lt;/option&gt; # &lt;option value="12" &lt;?PHP if($month==12) echo "selected";?&gt;&gt;December&lt;/option&gt; # &lt;/select&gt; # # &lt;select name="day" id="day"&gt; # &lt;option value="1" &lt;?PHP if($day==1) echo "selected";?&gt;&gt;1&lt;/option&gt; # &lt;option value="2" &lt;?PHP if($day==2) echo "selected";?&gt;&gt;2&lt;/option&gt; # &lt;option value="3" &lt;?PHP if($day==3) echo "selected";?&gt;&gt;3&lt;/option&gt; # &lt;option value="4" &lt;?PHP if($day==4) echo "selected";?&gt;&gt;4&lt;/option&gt; # &lt;option value="5" &lt;?PHP if($day==5) echo "selected";?&gt;&gt;5&lt;/option&gt; # &lt;option value="6" &lt;?PHP if($day==6) echo "selected";?&gt;&gt;6&lt;/option&gt; # &lt;option value="7" &lt;?PHP if($day==7) echo "selected";?&gt;&gt;7&lt;/option&gt; # &lt;option value="8" &lt;?PHP if($day==8) echo "selected";?&gt;&gt;8&lt;/option&gt; # &lt;option value="9" &lt;?PHP if($day==9) echo "selected";?&gt;&gt;9&lt;/option&gt; # &lt;option value="10" &lt;?PHP if($day==10) echo "selected";?&gt;&gt;10&lt;/option&gt; # &lt;option value="11" &lt;?PHP if($day==11) echo "selected";?&gt;&gt;11&lt;/option&gt; # &lt;option value="12" &lt;?PHP if($day==12) echo "selected";?&gt;&gt;12&lt;/option&gt; # &lt;option value="13" &lt;?PHP if($day==13) echo "selected";?&gt;&gt;13&lt;/option&gt; # &lt;option value="14" &lt;?PHP if($day==14) echo "selected";?&gt;&gt;14&lt;/option&gt; # &lt;option value="15" &lt;?PHP if($day==15) echo "selected";?&gt;&gt;15&lt;/option&gt; # &lt;option value="16" &lt;?PHP if($day==16) echo "selected";?&gt;&gt;16&lt;/option&gt; # &lt;option value="17" &lt;?PHP if($day==17) echo "selected";?&gt;&gt;17&lt;/option&gt; # &lt;option value="18" &lt;?PHP if($day==18) echo "selected";?&gt;&gt;18&lt;/option&gt; # &lt;option value="19" &lt;?PHP if($day==19) echo "selected";?&gt;&gt;19&lt;/option&gt; # &lt;option value="20" &lt;?PHP if($day==20) echo "selected";?&gt;&gt;20&lt;/option&gt; # &lt;option value="21" &lt;?PHP if($day==21) echo "selected";?&gt;&gt;21&lt;/option&gt; # &lt;option value="22" &lt;?PHP if($day==22) echo "selected";?&gt;&gt;22&lt;/option&gt; # &lt;option value="23" &lt;?PHP if($day==23) echo "selected";?&gt;&gt;23&lt;/option&gt; # &lt;option value="24" &lt;?PHP if($day==24) echo "selected";?&gt;&gt;24&lt;/option&gt; # &lt;option value="25" &lt;?PHP if($day==25) echo "selected";?&gt;&gt;25&lt;/option&gt; # &lt;option value="26" &lt;?PHP if($day==26) echo "selected";?&gt;&gt;26&lt;/option&gt; # &lt;option value="27" &lt;?PHP if($day==27) echo "selected";?&gt;&gt;27&lt;/option&gt; # &lt;option value="28" &lt;?PHP if($day==28) echo "selected";?&gt;&gt;28&lt;/option&gt; # &lt;option value="29" &lt;?PHP if($day==29) echo "selected";?&gt;&gt;29&lt;/option&gt; # &lt;option value="30" &lt;?PHP if($day==30) echo "selected";?&gt;&gt;30&lt;/option&gt; # &lt;option value="31" &lt;?PHP if($day==31) echo "selected";?&gt;&gt;31&lt;/option&gt; # &lt;/select&gt; # # &lt;select name="year" id="year"&gt; # &lt;?PHP for($i=date("Y"); $i&lt;=date("Y")+2; $i++) # if($year == $i) # echo "&lt;option value='$i' selected&gt;$i&lt;/option&gt;"; # else # echo "&lt;option value='$i'&gt;$i&lt;/option&gt;"; # ?&gt; # &lt;/select&gt;


How can you pass a JavaScript value into a PHP file?

JavaScript lives in the browser, PHP lives on the server.To pass a value from JavaScript to a PHP page, you can eitherdo an HTML form submituse AJAXIn both cases, the value is sent to the server and you write your PHP to handle it and send a response.The important thing is that the JavaScript value won't be available in PHP when you first generate the page, creating the page and handling the value submitted from the browser are two distinct steps.


What is the result if you use an input text in php?

$_POST is used see below for how. Firstly, in your form add a hidden feild: &lt;input type="hidden" name="hasposted" value="true" /&gt; Somewhere in your form. Then above the form add the following: &lt;?php if($_POST['hasposted'] '1'){ $mycheckbox = true; } else { $mycheckbox = false; } echo '$mytext ' . $mytext . '&lt;br /&gt;$mycheckbox '. $mycheckbox; } ?&gt; &lt;form method="POST" action="#"&gt; &lt;input type="hidden" name="hasposted" value="true" /&gt; &lt;label&gt;Textbox: &lt;input type="text" value="" name="mytext" /&gt;&lt;/label&gt;&lt;br /&gt; &lt;label&gt;Checkbox: &lt;input type="checkbox" value="1" name="mycheckbox" /&gt;&lt;br /&gt; &lt;br /&gt; &lt;input type="submit" value="Post" /&gt; &lt;/form&gt; I've posted links to W3Cschools with information on these and all other Form Elements.


How do you do the pass the variable value to the query in same php page?

To pass PHP Variable value in Jquery simpley echo that variable : Eg &lt;script&gt; var jQueryVariable=&lt;?php echo $anyVariable?&gt; &lt;/script&gt;