Zend Framework: unable to set default values ​​for part of elements with multiple cells

I am writing this question because I am having difficulty setting default values ​​for the _MultiCheckbox element in Zend Framework 1.9.3. I create a Zend_Form_Element_MultiCheckbox with several parameters:

$multiCheckbox = new Zend_Form_Element_MultiCheckbox( 'elId',
array ( 'disableLoadDefaultDecorators' =>true ) );

$multiCheckbox ->setName( 'elId' )
->setLabel('elId')
->setRequired( false )
->setAttrib('class', 'inputtext')
->setDecorators( array( 'ViewHelper' ) )
->setMultiOptions( $options );

where the $ options array is an associative array of 'key' => 'value'. The field is displayed just fine, and I can get all the checked values ​​for this element.

When returning to this page, I need to restore the entire list of parameters from the list again and mark the marked ones. I tried to do it like this:

$multiCheckbox ->setValue( $defaults );

$default - , 'checked_option_field_id' = > true
(, array ('1222' = > true, '1443' = > true)).
, , , setValue(). , "checked_option_field_id",
(, array ('1222', '1443'))
, - NONE . setDefaults() , , setValue() .

MultiCheckbox ( ):

<label for="elId-1222"><input type="checkbox" name="elId[]" id="elId-1222" value="1222" checked="checked" class="inputtext">BoRoom </label><br />

<label for="elId-1443"><input type="checkbox" name="elId[]" id="elId-1443" value="1443" checked="checked" class="inputtext">BoRoom Eng2 </label><br/>

elId []. . formDefaults() , setDefault() setValue(). , multicheckbox elId ( ) , .

, , multicheckbox.

+3
3

, setValue() , "" ( bool, ).

, Zend_Form_Element ( ), Zend_View_Helper. , Zend_View_Helper_FormRadio.

HTML , - setValue(), in_array().

Zend_View_Helper_FormRadio: 150

// is it checked?
$checked = '';
if (in_array($opt_value, $value)) {
    $checked = ' checked="checked"';
}

, , :

$element->setMultiOptions(array('1111' => 'Some Label', 
                                '2222' 'Some Other Label', 
                                '3333', 'Not Selected Label'));

$element->setValue(array('1111','2222');

. , - , , ?

+8

setValue() , , , , 1222, 1443, .

+2

You need to serialize the value of the flag before inserting it into the database. To display the database value again, you need to unserialize the displayed data.

Details that you can read at the following link.

http://abser-web-tips.blogspot.com/2010/09/zend-framework-multiple-check-box.html

thanks

+1
source

Source: https://habr.com/ru/post/1718826/


All Articles