开发者

Keeping Zend_Form from Rendering <form> tag

I have a case where the UX/Designer laid out a form design that requires me to create the <form></form> tags on my own in the phtml template, rather than have Zend_Form automatically generate them due to some non input related markup I need to fill in.

How do you keep Zend_Form from rendering the form tags? I wrote the following override of the render function that could surely be improved upon, but I can't seem to do anything by manipulating the decorators.

public function render(Zend_View_Interface $view = null)
    {
        $content = parent::render($view);
        $content = str_replace('</form&开发者_开发百科gt;','',$content);
        $idx = strpos($content,'>',4) + 1;
        $content = substr($content,$idx);
        return $content;
    }


If I read your question correctly, the answer is quite simple:-

$form = new Zend_Form();
$text = new Zend_Form_Element_Text('text');
$text->setLabel('text');
$form->addElement($text);
$form->removeDecorator('form'); // the bit you are looking for :)
Zend_Debug::dump($form->render());

Gives the following output:-

<dl class="zend_form">
    <dt id="text-label">
        <label for="text" class="optional">text</label>
    </dt>
    <dd id="text-element">
        <input type="text" name="text" id="text" value="">
    </dd>
</dl>

ie no <form> tag rendered. I think that is what you need.

If you want to do this in every form automatically by extending Zend_Form then overiding the render() method as follows works:-

public function render(Zend_View_Interface $view = null) 
{
    $this->removeDecorator('form');
    $content = parent::render($view);
    return $content;
}

I imagine that's a more satisfactory solution for you than doing it seperately for each individual form.


You're looking for the Zend_Form_Decorator_Form within Zend_Form.

$form->setDecorators(array(
    'Form',
    array(array('tag' => 'HtmlTag'), array('tag' => '')),
));

should work.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜