vinpkl
February 7, 2012, 10:58am
1
hi all
How can i get value from checkbox and echo that value
i have this below checkbox code for all my products in the row
<?
echo "<input name='availability[]' type='checkbox' onclick='this.form.submit();'
value='savl=Store&pidd=310' id='availability[]' />Store";
?>
Onclick the form gets submit but i dont get its value;
<?
if(isset($_REQUEST['availability']))
{
$savl=$_REQUEST['savl'];
$pidd=$_REQUEST['pidd'];
echo $savl; /* no value is echo */
echo $pidd; /* no value is echo */
}
?>
am i doing something wrong
vineet
I would use $_GET instead of $_REQUEST (to be sure you’re using the correct values).
To know why your code isn’t working, do a print_r of $_REQUEST and see what it contains.
vinpkl
February 7, 2012, 11:41am
3
Hi guido
after doing print_r also i dont get any values for $savl and $pidd
Array
(
[dealer_id] => 9
[category_id] => 1
[sub_catg] => 6
[availability] => Array
(
[0] => savl=Store&pidd=340
)
[PHPSESSID] => 2622124c72fa9bd4507a38e0a558dac0
)
Is there any other method of passing values to checkbox and then use them
vineet
The values are been past as you can see in your print_r statement, the reason why they are not part of the $_GET superglobal is because they are a value of the checkbox and not of the form action. You can use something simple like the below example to access the values.
if (isset($_GET['availability']) && sizeof($_GET['availability'])) {
foreach ($_GET['availability'] as $availability) {
$split = explode('&', $availability);
foreach ($split as $v) {
$temp = explode('=', $v);
echo 'Key: ' . $temp[0] . '<br>';
echo 'Value: ' . $temp[1] . '<br><br>';
}
}
}
vinpkl
February 7, 2012, 12:13pm
5
thanks chris
your solution works great
vineet
chris_upjohn:
The values are been past as you can see in your print_r statement, the reason why they are not part of the $_GET superglobal is because they are a value of the checkbox and not of the form action. You can use something simple like the below example to access the values.
if (isset($_GET['availability']) && sizeof($_GET['availability'])) {
foreach ($_GET['availability'] as $availability) {
$split = explode('&', $availability);
foreach ($split as $v) {
$temp = explode('=', $v);
echo 'Key: ' . $temp[0] . '<br>';
echo 'Value: ' . $temp[1] . '<br><br>';
}
}
}