Custom Decorator Label in Zend Framework 2

513 views Asked by At

according to this post: Zend Framework 2 - Form Element Decorators , i've tried the solution from iroybot (thanks to him) and it worked. but new problem occurs. Here the details:

In the render method in FormCollection.php (View Helper) i throw object like this:

<?php
 namespace Cust\View\Helper;

use Zend\Form\ElementInterface;
use Zend\Form\View\Helper\FormCollection as BaseFormCollection;

class  FormCollection extends BaseFormCollection
{
public function render(ElementInterface $element)
{


    return sprintf('<table  class="table table-condensed">%s</table>',parent::render($element));
}
}

and in the render method in FormElement.php (View Helper), i throw :

<?php
 namespace Cust\View\Helper;

 use Zend\Form\ElementInterface;
 use Zend\Form\View\Helper\FormElement as BaseFormElement;

 class FormElement extends BaseFormElement
{
public function render(ElementInterface $element)
{
    $req = '';
    if($element->getOption('required')){
        $req = 'required';
    }


    return sprintf('<tr><td>%s</td><td>%s</td>  </tr>',$element->getLabel(),parent::render($element));

}
}

and the form render in the table perfectly. but before table, the label show in the tag label. so the label display twice, first in span tag, and the second in the row of the table...

i don't know how to solve this..

please give me advice.. thanks

bestregards

0

There are 0 answers