2
I’m cracking my head to set a checkbox as marked.
I know the markup syntax (<input checked>) but this particular checkbox is being mounted from an array and I couldn’t, and I don’t even know if it’s possible, define how checked.
That 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 that part is responsible for the exhibition:
<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 another 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;
}
}
Marko, how are you converting this to HTML?
– Sergio
That is, the only part responsible for that field that I found was on that page on that array. I tried searching the other pages for an array call: 'id' => 'enable_public_questions', but could not find on any page
– Marko Neto
A little further down the page I found the call that mounts the $array Return; }
– Marko Neto
There is a
echosomewhere that sends it to the client side?– Sergio
foreach ((array) $this->_multiOptions as $key => $option) {
 $checked = (in_array($key, (array) $value)) ? ' checked="checked" ' : '';the party responsible for marking ascheckedThat’s the one, but you still can’t do much, because$valuereceives values from another functiongetValue, and in that part of your code you can’t see that function. But it’s basically this, it marks ascheckedthe values derived fromgetValuethat are on the arraymultiOptions.– Edilson