Tuesday, December 28, 2010

Set Form value in zend controller

Hiii

Zend is really a good framework for hire level application but still not for small level because of its lack of good documentation on the small issue which is genrally need in daily web development task .....


I am giving details here that how do we can set a form value again if it is comming by post in the Zend form.

There is 3 field on the zend form you can get a lot of guide on how to create form in zend then if post back then you have to set the value by

$this->getForm()->sort_by->setvalue($request->getParam('sort_by'));



public function filterAction()
    { 
        $request = $this->getRequest();
        if($this->getRequest()){
                   $this->getForm()->filter_field->setvalue($request->getParam('filter_field')); $this->getForm()->sort_by->setvalue($request->getParam('sort_by'));
     $this->getForm()->filter_value->setvalue($request->getParam('filter_value'));   
        }




public function indexAction()
    {
        $auth = Zend_Auth::getInstance();
        if(!$auth->hasIdentity()) {           
            $this->_redirect('index/login');                       
        }else{
           
            $role = Zend_Auth::getInstance()->getIdentity()->usertype_id;
            if($role != 1 ){
              $this->_redirect('dashboard/index');
            }
            $this->view->form = $this->getForm();
      }



public function getForm() {
        if (null === $this->_form) {
            $this->_form = new Application_Form_AdminUserFilter();
        }
        return $this->_form;
    }




This is how we can overcome the form value get form post problem...
I'll explain in my next blog how to apply pagination on the search result in zend

Thanks
Deepak
India