How to use data from Zend_Db_Table in a Zend_Form

I have create a form class for editing deleting and add users to a database. If I want to edit a user how can I simply supply the information of the user to the form.

I use a Zend_Db_Table to get the data from the 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 you,

Ivo Trompert

Answers


This is done with:

$form->populate($data);

where $data is an array with your table-row-data where the field names have to match the ones from the form. Zend will do the rest.


one of the 'fetchXXX' or 'find' methods on your extended Db_Table will return a Rowset, calling current() on that will give you a Row, which has a toArray method that will give you the format tharkun's response is asking for.


Need Your Help

Jquery/JavaScript String Match

javascript jquery

I have compare Two strings.If str1 matches 80% of str2 then it should return true. else it should return false.

How can I tell if Voice Over is turned on in System Preferences?

cocoa macos macos-carbon assistive

Is there an way, ideally backwards compatible to Mac OS X 10.3, to tell if "Voice Over" is activated in System Preferences?