Zend Framework multiple checkbox
I have a multiple check box in zend framework where I have to diaplay image in place of label.
For example:
<label for="elId-1222">
<input type="checkbox" name="elId[]" id="elId-1222" value="1222" checked="checked" class="inputtext">
<image src="images/yes.png">
</label><br />
So in multioptions I have prepared an array of key and value pair, but how will I be able to add an image in place of value so that above image get displayed in label. My code is as shown below:
$multiCheckbox = new Zend_Form_Element_Mu开发者_开发问答ltiCheckbox( 'elId', array ( 'disableLoadDefaultDecorators' =>true ) );
$multiCheckbox ->setName( 'elId' )
->setLabel('elId')
->setRequired( false )
->setAttrib('class', 'inputtext')
->setDecorators( array( 'ViewHelper' ) )
->setMultiOptions( $options );
You can do this by using Decorator ViewScript
For example, this is my case:
$fanpages = $this->addElement('MultiCheckbox', 'fanpages', array(
'label' => 'Fanpages',
'id' => 'fanpages',
));
//Don't check where value come from
$this->getElement('fanpages')->setMultiOptions(array())
->setRegisterInArrayValidator(false);
$this->getElement('fanpages')->setDecorators(array(array('ViewScript', array(
'viewScript' => 'loadMyFanpages.phtml',
'class' => 'form_element'
))));
views/script/loadMyFanpage.phtml
<ul class="jp_listfan">
<?php foreach ($this->element->getMultiOptions() as $option => $value): ?>
<li>
<input name="fanpages[]" value="<?php echo trim($option); ?>" type="checkbox"/><img src="your/url/images.jpg"/><?php echo trim($value); ?>
</li>
<?php endforeach; ?>
</ul>
You can print all element with custom HTML based on your need ^_^ hope this help.
精彩评论