I want to create a form with Zend Framework 2 for my application, and I have everything in place and the form is displayed, but my problem is that I cannot bind the initial values of the forms that come from the database
$myUserDetails = <details of my user coming from DB>; $form = $form->bind($myUserDetails);
My display logic is simple as below
$form = $this->form; $form->setAttribute('action', $this->url('<routename>',array('action'=>'<actionname>'))); $form->prepare(); echo $this->form()->openTag($form) . PHP_EOL; echo $this->formRow($form->get('email_id')) . PHP_EOL; echo $this->formRow($form->get('dob')) . PHP_EOL; echo $this->formRow($form->get('gender')) . PHP_EOL; echo $this->formRow($form->get('user_page_name')) . PHP_EOL; echo $this->formInput($form->get('submit')) . PHP_EOL; echo $this->form()->closeTag($form) . PHP_EOL;
Now I tried to set the data from my object, which I bind to the form in my controller action.
$myUserDetails = <details of my user coming from DB>; $form = $form->bind($myUserDetails); $data = $myUserDetails->getArrayCopy(); $form->setData($data['data']);
It seems to work somehow and display my values in the view. So I just want to know what I did wrong in my first approach? Thanks in advance:)
source share