Jump to content

Fetching values from checkboxes


Crezzur.com

Recommended Posts

Hey all

 

I need to retrieve the check-box value which are checked in an array.

 

My html code:

<th><span class="title_box">Category name</span></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="checkbox" name="catBox[]" class="groupBox" id="catBox_3" 
value="3" checked="checked" /></td>
<td><label for="catBox_3">Women</label></td>
</tr>
<tr>
<td><input type="checkbox" name="catBox[]" class="groupBox" id="catBox_12" 
value="12" checked="checked" /></td>
<td><label for="catBox_12">Male</label></td>
</tr>
<tr>
<td><input type="checkbox" name="catBox[]" class="groupBox" id="catBox_13" 
value="13" checked="checked" /></td>
<td><label for="catBox_13">Kids</label></td>
</tr>
</tbody>
</table>

Using the following PHP code:

Tools::getValue('catBox[]')

Does not return any data for some reason?

 

Solution: (use the right way to call a variable)

Tools::getValue('catBox')
Edited by Crezzur (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Hi Crezzur,

 

I think you should use this instead:

$catBoxes = Tools::getValue('catBox');

It will return an array of value:

foreach ($catBoxes as $cb) {
    // do smth
}

Hope this help.

 

Made a mistake with the Tools::getValue i used "Tools::getValue('catBox[]');" instead of "Tools::getValue('catBox');"

 

Did not see it earlier until you made you post so thank you ;)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...