I know, don't use tables for forms. Regardless, I'm trying to do just that.
Using Matthew's "Decorators with Zend_Form" I created the following code to
create a subform as a table with label/elements as row/cells. I then add the
subform 
to the form. I get the <table> wrapper arount the subform but the labels and
elements 
are merely rendered without any decorators. There are no <tr> or <td>
elements.

I'm sure I'm missing something here even though I copied the decorators
directly from the
article.

Any help please?
Code and results follow:

--------------------------------------------------------------------------------------------------------
$choices = new Zend_Form_SubForm;
foreach ($recs as $rec) {
        $a = $choices->createElement("text", $rec->value."_a")
                ->setRequired(false)
                ->setValue($cd[$i])
                ->setLabel($rec->label)
                ->setAttrib("class","")
       ;
        $a->setDecorators(array(
                'ViewHelper',
                 'Errors',
                array(array('data' => 'HtmlTag'), array('tag' => 'td','class' =>
'element')),
                array('Label', array('tag' => 'td')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
        ));
        
        $b = $choices->createElement("text", $rec->value."_b")
                ->setRequired(false)
                ->setValue($cd[$i])
                ->setAttrib("class","")
        ;
        $b->setDecorators(array(
                'ViewHelper',
                'Errors',
                array(array('data' => 'HtmlTag'), array('tag' => 'td','class' =>
'element')),
                array('Label', array('tag' => 'td')),
                array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
        ));

        $choices->addElements(array($a,$b));
        $i++;
}
$choices->setDecorators(array(
    'FormElements',
    array('HtmlTag', array('tag' => 'table')),
));
--------------------------------------------------------------------------------------------------------
$choices gets added to my form using addSubForm.

When my form is rendered, I do not get the <tr> or <td> tags.

Here is a snippet of what is rendered.
--------------------------------------------------------------------------------------------------------
<table>
<label for="Response-PLAS_a" class="optional">Plastic</label>
<input type="text" name="Response[PLAS_a]" id="Response-PLAS_a" value="10"
class="">
<input type="text" name="Response[PLAS_b]" id="Response-PLAS_b" value="10"
class="">

<label for="Response-STL_a" class="optional">Steel</label>
<input type="text" name="Response[STL_a]" id="Response-STL_a" value="-1"
class="">
<input type="text" name="Response[STL_b]" id="Response-STL_b" value="-1"
class="">

 . . . 

</table>
--------------------------------------------------------------------------------------------------------

-- 
View this message in context: 
http://www.nabble.com/Form-as-a-Table-tp19412892p19412892.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to