I'm creating a checkbox and assigning it to a smarty variable, outputted by a template.
$s = $this->CreateInputCheckbox($id,'mycheckbox' ,'1', $checkboxvalue );
$smarty->assign('input_mycheckbox',$s);
The checkbox is on the form, but only if the checkbox is checked, does it get returned in the $params array when the form is submitted.
Using the php:
print_r($params);
I don't get mycheckbox => anything if not checked.
It is not in the list of $params elements, there is no $params['mycheckbox']
Am I doing something wrong?
[Solved] Checkbox only in params if checked
[Solved] Checkbox only in params if checked
Last edited by tmk on Mon Jan 12, 2009 4:24 am, edited 1 time in total.
Re: Checkbox only in params if checked
tmk,
You are not doing anything wrong. That is basic functionality of a checkbox, if it's not checked then it is not passed via POST.
If you need to know if the checkbox is selected, you could use:
The code above will either assign the value of the checkbox to the variable if checked or else assign 0 to the variable.
You are not doing anything wrong. That is basic functionality of a checkbox, if it's not checked then it is not passed via POST.
If you need to know if the checkbox is selected, you could use:
Code: Select all
$mycheckboxvalue = $params["mycheckbox"]?$params["mycheckbox"]:0;
The code above will either assign the value of the checkbox to the variable if checked or else assign 0 to the variable.
Code: Select all
if($mycheckboxvalue){
echo "mycheckbox has been selected";
}else{
echo "mycheckbox has NOT been selected";
}