[Solved] Checkbox only in params if checked

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
tmk
Forum Members
Forum Members
Posts: 25
Joined: Sun Sep 23, 2007 4:07 am

[Solved] Checkbox only in params if checked

Post by tmk »

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?
Last edited by tmk on Mon Jan 12, 2009 4:24 am, edited 1 time in total.
irish
Forum Members
Forum Members
Posts: 101
Joined: Tue Jun 03, 2008 2:31 pm

Re: Checkbox only in params if checked

Post by irish »

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:

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";
}
Post Reply

Return to “Developers Discussion”