Checkbox marked automatically in array

2

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;
    }

}
    
asked by anonymous 19.12.2014 / 07:57

2 answers

-2

I have already resolved, I had to adapt a function that when the field was not selected I gave a return false, I changed to return true, and even without checking the field the problem was solved. This is what I need, but the question of setting it checked in the array is a mystery.

Thanks to all who are willing to help me.

    
21.12.2014 / 21:59
2

Try adding:

'values' => true,

or

'values' => array('value',true),

In some php settings with xml it's like this.

    
19.12.2014 / 19:51