ZF: Zend_Form_SubForm display elements in the View on one's own using only FormElements and ViewHelper?

499 Views Asked by At

My task is to create list of inputs which have name like photoForm[name][1]. If I do print $this->form in the view - that is ok. All fields are good.

But I don't wanna use decorator and I would like to compile on one's own. (just leave ViewHelper and FormElements for displaying in the View)

I run this code in the view:

foreach($this->mainform->getSubForm('photoForm')->getSubforms() as $form)
{
    foreach($form->getElements() as $element)
    {
        print $element;
    }
}

And get follow input:

<input type="text" name="name" id="name" value="" />

But I would like to see follow code instead:

<input type="text" name="photoForm[name][1]" id="photoForm-name-1" value="" />

How to print it correct?

This is my simplified source code for good understandig:

function addInput($name, $id, $value)
{
    global $photoForm;

    $input = new Zend_Form_Element_Text($name);
    $input->setValue($value);

    $subform = new Zend_Form_SubForm(();
    $subform->addElement($input);

    $photoForm->getSubForm('photoForm')->addSubForm($subform, $id);
}

function submitInput()
{
    $input = new Zend_Form_Element_Submit('submit');
    $input->setLabel('Save');

    return $input;
}

$photoForm = Zend_Form();

$subform = new Zend_Form_SubForm();

$photoForm->addSubForm($subform, 'photoForm');
$photoForm->addElement(submitInput());

addInput('name', 1, 'value');
1

There are 1 best solutions below

0
On BEST ANSWER