I have a Zend form to add something to the database. And then I want to use this form to edit what I added to the databese. Is it possible to use this form (fill it out from the database and display it?) I have this in the controller:
public function editAction() {
if (Zend_Auth::getInstance()->hasIdentity()) {
try {
$form = new Application_Form_NewStory();
$request = $this->getRequest();
$story = new Application_Model_DbTable_Story();
$result = $story->find($request->getParam('id'));
if ($this->getRequest()->isPost()) {
if ($form->isValid($request->getPost())) {
$data = array(
'title' => $form->getValue("title"),
'story' => $form->getValue("story"),
);
$where = array(
'id' => $request->getParam('id'),
);
$story->update($data, $where);
}
}
$this->view->form = $form;
$this->view->titleS= $result->title;
$this->view->storyS= $result->story;
} catch (Exception $e) {
echo $e;
}
} else {
$this->_helper->redirector->goToRoute(array(
'controller' => 'auth',
'action' => 'index'
));
}
}
In my opinion:
<?php
try
{
$tmp = $this->form->setAction($this->url());
}
catch(Exception $e)
{
echo $e;
}
And when I try to change something in this view, I mean giving any value other than NULL. I have a mistake that I cannot make, so is there any way to reuse this form? Or not?
Thank!
source
share