I'm breaking my head to set a checkbox as checked.
I know the syntax of the markup ( <input checked>
) but this particular checkbox is being assembled from an array and I could not, and I do not know if it's possible, set it as checked .
This is the code:
array(
'form_id' => 'global_settings',
'id' => 'enable_public_questions',
'element' => ($settings['enable_public_questions']) ? 'checkbox' : false,
'label' => $this->_('Accept Public Questions'),
'description' => $this->_('Check the above checkbox to allow site users to post public questions .'),
'multiOptions' => array(
1 => null,
),
),
array(
I believe this part is responsible for the display:
<global_settings>
<label>Global Settings</label>
<module>members</module>
<controller>tools</controller>
<action>global-settings</action>
<resource>Tools</resource>
<privilege>GlobalSettings</privilege>
</global_settings>
I found one more part:
class Checkbox extends Element
{
/**
*
* type of element - override the variable from the parent class
*
* @var string
*/
protected $_element = 'checkbox';
public function render()
{
$output = null;
$value = $this->getValue();
$multiple = '';
if (count((array) $this->_multiOptions) > 1 || $this->getMultiple() === true) {
$multiple = $this->_brackets;
}
$output .= '<input type="hidden" name="' . $this->_name . $multiple . '" value=""'
. $this->_endTag;
foreach ((array) $this->_multiOptions as $key => $option) {
$checked = (in_array($key, (array) $value)) ? ' checked="checked" ' : '';
if (is_array($option)) {
$title = $option[0];
$description = $option[1];
}
else {
$title = $option;
$description = null;
}
$output .= '<label class="checkbox">'
. '<input type="' . $this->_element . '" name="' . $this->_name . $multiple . '" value="' . $key . '" '
. $this->renderAttributes()
. $checked
. $this->_endTag
. ' ' . $title
. ((!empty($description)) ? '<span class="help-block">' . $description . '</span>' : '')
. '</label>'
. "\n";
}
return $output;
}
}