5 Replies - 1326 Views - Last Post: 23 May 2010 - 07:07 PM Rate Topic: -----

#1 ptamzz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 103
  • Joined: 04-March 09

getting checked box using post method (form processing)

Posted 23 May 2010 - 07:00 AM

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
Is This A Good Question/Topic? 0
  • +

Replies To: getting checked box using post method (form processing)

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,222
  • Joined: 23-August 08

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?
Was This Post Helpful? 1
  • +
  • -

#3 ptamzz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 103
  • Joined: 04-March 09

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
Was This Post Helpful? 0
  • +
  • -

#4 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 143
  • View blog
  • Posts: 715
  • Joined: 16-September 08

Re: getting checked box using post method (form processing)

Posted 23 May 2010 - 09:53 AM

Look at the lines below-
<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.
Was This Post Helpful? 0
  • +
  • -

#5 ptamzz  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 103
  • Joined: 04-March 09

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,
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???
Was This Post Helpful? 0
  • +
  • -

#6 atik97  Icon User is offline

  • ???
  • member icon

Reputation: 143
  • View blog
  • Posts: 715
  • Joined: 16-September 08

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-

<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.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1