开发者

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

My task is to create list of inputs which have name like phot开发者_StackOverflow社区oForm[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');


So I found an answer.

Courtesy https://stackoverflow.com/users/220922/fimbulvetr

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜