can anyone please explain how to get the checked box from a form with checkboxes using post method??
or please direct me to a good tutorial for it suitable for a beginners level...
thanks
5 Replies - 1184 Views - Last Post: 23 May 2010 - 07:07 PM
#1
getting checked box using post method (form processing)
Posted 23 May 2010 - 07:00 AM
Replies To: getting checked box using post method (form processing)
#2
Re: getting checked box using post method (form processing)
Posted 23 May 2010 - 07:29 AM
You mean, like this one in our tutorials area?
#3
Re: getting checked box using post method (form processing)
Posted 23 May 2010 - 09:38 AM
Yes but i am still confused with a few things.
What do we get in the global variable $_POST[checkBoxName]??? Is is an array of the checked items or on/off state or something else??
Thanks
What do we get in the global variable $_POST[checkBoxName]??? Is is an array of the checked items or on/off state or something else??
Thanks
#4
Re: getting checked box using post method (form processing)
Posted 23 May 2010 - 09:53 AM
Look at the lines below-
In the first case, $_POST["status"] will hold the value "on" if the box is checked. On the other hand, second case it will hold the value of "agree" in case it is checked and submitted. So you might have already idea that the default value of checkbox is on/off, but when value attribute is present in <input> tag, that value will be hold on the variable when it is enabled.
<input type="checkbox" name="status"/>Agree <input type="checkbox" name="status" value="agree"/>Agree
In the first case, $_POST["status"] will hold the value "on" if the box is checked. On the other hand, second case it will hold the value of "agree" in case it is checked and submitted. So you might have already idea that the default value of checkbox is on/off, but when value attribute is present in <input> tag, that value will be hold on the variable when it is enabled.
#5
Re: getting checked box using post method (form processing)
Posted 23 May 2010 - 11:18 AM
Thank you. That clears me up a lot.
One more thing. If I select multiple checkboxes, what do i check in the processing part??
something like,
will this store the values of all the checkboxes in the $name variable in the form of an array???
One more thing. If I select multiple checkboxes, what do i check in the processing part??
something like,
if(isset($_POST['status']){
$names = $_POST['status'];
}
will this store the values of all the checkboxes in the $name variable in the form of an array???
#6
Re: getting checked box using post method (form processing)
Posted 23 May 2010 - 07:07 PM
Yes, all the values will be stored in the $names array.
As you might already know, in case of multiple checkbox, you need to use name attribute like this-
Then in the processing script, $_POST["status"] will contain all the checked values in the form of array.
As you might already know, in case of multiple checkbox, you need to use name attribute like this-
<input type="checkbox" name="status[]" value="value1">Value1 <input type="checkbox" name="status[]" value="value2">Value2
Then in the processing script, $_POST["status"] will contain all the checked values in the form of array.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|