How to use data from Zend_Db_Table in Zend_Form
I created a form class for deleting and adding users to the database. If I want to edit the user, how can I just provide the user information to the form.
I am using Zend_Db_Table to get data from a database.
This is the userForm class:
class UsersForm extends Zend_Form
{
public function init ()
{
$username = new Zend_Form_Element_Text('username',array(
'validatrors' => array(
'alpha',
array('stringLength',5,10)
),
'filters' => array(
'StringToLower'
),
'required' => true,
'label' => 'Gebruikersnaam:'
));
$password = new Zend_Form_Element_Password('password', array(
'validators'=> array(
'Alnum',
array('StringLength', array(6,20))
),
'filters' => array('StringTrim'),
'required' => true,
'label' => 'Wachtwoord:'
));
$actif = new Zend_Form_Element_Checkbox('actif', array(
'label' => 'actif'));
$this->addElements(array($username,$password,$actif));
$this->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form')),
array('Description',array('placement' => 'prepand')),
'Form'
));
}
}
Thank,
Ivo Trompert
+1
Ivo Trompert
source
to share
2 answers
This is done with:
$form->populate($data);
where $ data is an array with your table-table data, where the field names must match the names from the form. Zend will do the rest.
+4
markus
source
to share
one of the "fetchXXX" or "find" methods on the extended Db_Table will return a Rowset by calling current (), which will give you a string that has a toArray method that will give you the tharkun response format. for.
0
Greg
source
to share