I have a controller with this action below:
public function addAction()
{
//action for the comments submission
$form = new Application_Form_Comment();
$form->submit->setLabel('Comment');
$this->view->form = $form;
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
if ($form->isValid($formData)) {
$comment = new Application_Model_DbTable_Comments();
$comment->addComment($formData['comment'], $id);
$this->_helper->redirector('index');
} else {
$form->populate($formData);
}
}
In my view if I echo $this->form;
The form doesn’t show.
Rik
Assuming you are trying to separate the form from any particular controller, you could use a view helper. Writing your own is quite easy.
Create the file
application/views/helpers/CommentForm.phpwhich will contain:-Then in whichever view you need it in just do:-
Which will render your form.