Удалить HTML-теги из Zend_Form - PullRequest
2 голосов
/ 05 июня 2011

Я хочу получить простую форму HTML:

<form method="post"> 
<input type="text" name="question" id="question" value="" size="50%">
<input type="submit" name="ask" id="ask" value="Ask">
</form>

Что я получаю с Zend Framework:

<form enctype="application/x-www-form-urlencoded" method="post" action=""> 
<dt id="question-label">&#160;</dt> 
<dd id="question-element"> 
<input type="text" name="question" id="question" value="" size="50%"></dd> 
<dt id="ask-label">&#160;</dt><dd id="ask-element"> 
<input type="submit" name="ask" id="ask" value="Ask"></dd>
</form>

Как я могу удалить ненужные HTML-теги (дд, дт)?

Ответы [ 3 ]

3 голосов
/ 06 июня 2011

Я нашел похожий вопрос, и ответ на него привел меня к использованию следующего решения (которое работает для меня):

$form->setElementDecorators(array('ViewHelper','Errors'));
0 голосов
/ 17 августа 2011

Полный контроль над выводом формы без обхода логики / фильтрации / проверки формы The View:</p> <pre><code><form action="<?php echo $this->form->getAction(); ?>" method="<?php echo $this->form->getMethod(); ?>"> <!-- Errors For question field--> <?php echo (NULL != ($errors = $this->form->getElement('question')->getMessages()) ? $this->formErrors($errors) : ''); ?> <!-- question field --> <?php echo $this->form->getElement('question')->renderViewHelper(); ?> <!-- Submit Field --> <?php echo $this->form->getElement('submit')->renderViewHelper(); ?> </form>

Конец

The Form</p> <pre><code><?php class Form_Question extends Zend_Form { public function init() { $this->setMethod(self::METHOD_POST); $element = $this->createElement('text', 'question'); $element->setLabel('Question'); $element->setRequired(TRUE); $element->removeDecorator('DtDdWrapper'); $element->setAttrib('class', 'text'); $this->addElement($element); $element = $this->createElement('submit', 'submit'); $element->setLabel('Submit'); $element->setRequired(TRUE); $element->removeDecorator('DtDdWrapper'); $element->removeDecorator('label'); $this->addElement($element); } }

конец формы

the controller action</p> <pre><code> public function questionAction() { $form = new Form_Question(); if($this->getRequest()->isPost()) { if($form->isValid($this->getRequest()->getPost())) { // Do stuff } else { $this->_helper->FlashMessenger(array('error' => "Errors! Correct the errors in the form below")); } } $this->view->assign('form', $form); }

действие конечного контроллера

0 голосов
/ 06 июня 2011

Вы можете использовать -> removeDecorator («DtDdWrapper»);удалить оболочки dt и dd.

...