Summary:
CSS class for Check Box not being applied to input tag
Detailed Description:
I noticed that the CSS class field on the advanced setting tab for check box
type field was being ignored in the rendered form code.
I took a look at the class file CheckBoxField.class.php and saw the problem at
line 45 in the GetFieldInput function which is calling the CreateInputCheckbox
method of the (deprecated) CMS Module class.
This does not include the CSS class value at all. And I noticed another problem
when I was trying to overcome this by manually generating the checkbox input tag
- it did not remember its setting if there were invalid fields present on the
form.
I have done a major hack on this GetFieldInput function code so that the class
property is included as well as overcoming the problem about remembering if it
was previously checked.
I suspect there is a similar problem in the CheckboxGroupField.class.php and
CheckboxExtendedField.class.php as they are both using the CreateInputCheckbox
method.
Also, there is a function in the class.formbuilder_utils.php which I suspect is
not used:
lines 185-209 function create_input_checkbox ...
So, here is my complete hack for the GetFieldInput function, including some
commented-out debugging lines at end:
function GetFieldInput($id, &$params, $returnid)
{
$mod = formbuilder_utils::GetFB();
$label = '';
$html5 = '';
$checked = '';
$js = $this->GetOption('javascript','');
$css_class = $this->GetOption('css_class');
$cssid = $this->GetCSSId();
$name = $id.'fbrp__'.$this->Id;
if ($this->GetOption('html5','0') == '1'&& $this->IsRequired())
{
$html5 = ' required';
}
if (strlen($this->GetOption('label','')) > 0)
{
$label = ' <label
for="'.$cssid.'">'.$this->GetOption('label').'</label>';
}
if ( ($this->Value === false && $this->GetOption('is_checked','0')=='1') ||
$this->Value == $this->GetOption('checked_value','0') )
{
$this->Value = $this->GetOption('checked_value');
$checked = ' checked="checked"';
}
$text = '<input type="checkbox" class="'.$css_class.'" name="'.$name.'"
id="'.$cssid.'" value="'.$this->GetOption('checked_value').'"'.$checked;
$text .= " />\n";
/* for debugging*/
/*
echo "Checked value is : ".$this->GetOption('checked_value').'<br>';
echo "Unchecked value is : ".$this->GetOption('unchecked_value').'<br>';
echo "Option - is_checked : ".$this->GetOption('is_checked','0').'<br>';
echo "Value is : ".$this->Value;
*/
return $text.$label;
}