How change standard decoration in zend form -
in directory form have formarena
$this->addelement('radio', 'warrior',array( 'decorators' => array( 'viewhelper', ), 'disableloaddefaultdecorators' => true, 'separator' => '', ));
on view page have
<?php echo $this->forms['formarena']->getitem('warrior'); ?>
and in controller have
$getwarriorslist = $this->objarena->getactiveusers($this->varuserdata['id']); $objformarena = new formarena(); if (!empty($getwarriorslist)){ foreach($getwarriorslist $varwarriors) $varoptions[$varwarriors['id_users']] = $varwarriors['nick']; $objformarena->warrior->addmultioptions($varoptions); unset($varoptions); } $this->view->forms = array( 'formarena' => $objformarena, );
ok easy. take data base , add option view controller. when see source code on page have:
<div class="radio"> <label for="warrior-27"> <input type="radio" name="warrior" id="warrior-27" value="27">makapaka</label> <label for="warrior-29"> <input type="radio" name="warrior" id="warrior-29" value="29">kasia</label> </div>
but need
<div class="radio"> <input id="warrior-27" type="radio" name="warrior" value="27"> <label for="warrior-27">makapaka</label> <input id="warrior-29" type="radio" name="warrior" value="29"> <label for="warrior-29">kasia</label> </div>
what should need do. tried search web have still nothing 2 days :(
the current option not allow rendering in exact format wished.
it can either
<div class="radio"> <label for="warrior-27"> <input type="radio" name="warrior" id="warrior-27" value="27">makapaka</label> <label for="warrior-29"> <input type="radio" name="warrior" id="warrior-29" value="29">kasia</label> </div>
or
<div class="radio"> <label for="warrior-27"> makapaka <input type="radio" name="warrior" id="warrior-27" value="27"></label> <label for="warrior-29"> kasia <input type="radio" name="warrior" id="warrior-29" value="29"></label> </div>
to render form element mentioned, need create either custom view helper , pass option viewhelper
decorator or use viewscript
decorator generate custom output.
personally, prefer viewscript
decorator easy of use.
example of use :
$this->addelement('radio', 'warrior',array( 'decorators' => array( array('viewscript', array('viewscript' => 'decorator.phtml')) ) ));
and in decorator.phtml
<div class="radio"> <?php foreach($this->element->getmultioptions() $value => $label): ?> <input id="<?php echo $this->element->getname() ?>-<?php echo $value ?>" type="radio" name="<?php echo $this->element->getname() ?>" value="<?php echo $value ?>"> <label for="<?php echo $this->element->getname() ?>-<?php echo $value ?>"><?php echo $label ?></label> <?php endforeach ?> </div>
nb : script file can used form radio elements
hope helps
Comments
Post a Comment