Reputation: 2377
I want to edit particular row of table, before I want to show existing data in my form.
To show from i am using form decorator.
If I comment form decorator IT works fine.
I used $form->populate($row); but its not filling form.
Please view below code for adminController.php
public function indexAction() {
$form = new Application_Form_articleForm();
$this->view->form = $form;
$content = new Application_Model_Content();
$id = $this->_request->getParams('id');
$row = $content->find($id)->toArray();
$form->populate($row[0]);
}
model file
<?php
class Application_Model_Content extends Zend_Db_Table
{
protected $_name = "content";
}
Form
<?php
class Application_Form_articleForm extends Zend_Form
{
public function init()
{
$this->setMethod('post');
$id = $this->createElement('hidden','id');
$content_name = $this->createElement('text','content_name');
$content_name->setLabel('URL name:')
->setAttrib('size',250);
$this->addElements(array(
$id,
$content_name
));
$this->setDecorators(array(array('viewScript', array('viewScript' => 'admin/articleFormDecorator.phtml'))));
}
}
articleFormDecorator.phtml
<form action="" method="post" enctype="application/x-www-form-urlencoded">
<header><h3>Post New Article</h3></header>
<div class="module_content">
<fieldset>
<label>URL name</label>
<input type="hidden" name="id" id="id">
</fieldset>
<fieldset>
<label>Content</label>
<textarea rows="12" name="content_name" id="content_name"></textarea>
</fieldset>
Please help me to get the values in form.
Upvotes: 0
Views: 357
Reputation: 2377
I got the solution We need to add below line with form element in form
$content_name = $this->createElement('text','content_name');
$content_name->setLabel('URL name:')
->setAttrib('size',250);
and to show form element in html write as below in form decorator file
<?php echo $this->element->content_name ?>
Upvotes: 0
Reputation: 1567
you can add condition like this,
if ($this->getRequest()->isPost())
then the procedure for updating the values and storing them in databse
and in else part, you can populate the form like,
else{
$id = $this->_getParam('id', 0);
if ($id > 0) {
$row = $content->find($id)->toArray();
$form->populate($row[0]);
}
Upvotes: 1