Hi there,I had build a entity object which implements
InputFilterAwareInterface to supply filters to forms and implements 
ArraySerializableInterface to get data exchanged to my entity after
validation.Without binding the object and setting the inputputers and data
manually the invalidate and getdata() from the form object are working as
expected (i.e the values are getting passed and retrieved in full, actually
I have 4 input elements out of which two has input validators).If I bind the
the entity object the exchangearray call gives me empty data and another
only the fields in the validators is passed. what actually I do is1. fill
the entity object with exchange array2. bind entity object to form3. call
isvalidthe form is getting the data, input filters from entity, and
validation is passing through after but after validation the call to
exchange array only shows empty data of the items that have validators
others values are missing.below are my validators and binding codes
//function inside formclass AbstractEntity{ protected function
addFilter($elementName, $validators = array(), $filters = array()){       
$inputFilters = array();        $inputValidators = array();       
if($this->inputFilters->offsetExists($elementName)){           
$existingFilters = $this->inputFilters->offsetGet($elementName);           
if(isset($existingFilters['filters'])){                $inputFilters =
$existingFilters['filters'];            }           
if(isset($existingFilters['validators'])){                $inputValidators =
$existingFilters['validators'];            }        }       
if(!empty($filters)){            $inputFilters[] = $filters;        }       
if(!empty($validators)){            $inputValidators[] = $validators;       
}        $elementFilter = array(            'name' => "$elementName",           
'required' => true,            'filters' => $inputFilters,           
'validators' => $inputValidators        );        if(!empty($inputFilters)){    
       
$elementFilter['filters'] = $inputFilters;        }       
if(!empty($inputValidators)){            $elementFilter['validators'] =
$inputValidators;        }       
$this->inputFilters->offsetSet($elementName, $elementFilter);    }    public
function getInputFilter() {        $inputFilter = new InputFilter();       
$factory = new InputFactory();                    $iterator =
$this->inputFilters->getIterator();        while($iterator->valid()) {          
 
$inputFilter->add($factory->createInput($iterator->current()));           
$iterator->next();        }        return $inputFilter;    }}// implemented
formclass MyForm extends AbstractForm{    public function getInputFilter() {    
   
//include filters and validator for the entity form       
$this->addFilter('companyname', array('name' => 'NotEmpty', 'options' =>
array('messages' => array('isEmpty' => 'Company name cannot be empty'))));      
 
$this->addFilter('address', array('name' => 'NotEmpty', 'options' =>
array('messages' => array('isEmpty' => 'Address cannot be empty'))));       
//include unique field validator        $noRecordExist = new NoRecordExists(    
       
array(                'table' => $this->getTableName(),               
'field' => $this->getUniqueField(),                'adapter' =>
$this->getDbAdapter(),            )        );       
$noRecordExist->setMessage('Company name already exist');       
if($this->id > 0){            $noRecordExist->setExclude(               
array(                    'field' => 'id',                    'value' =>
$this->id                )            );        }       
$this->addFilter('companyname', $noRecordExist);        return
parent::getInputFilter();    }}//Controller code            $companyForm =
new \Manage\Forms\CompanyForm();            $companyEntity =
$this->getServiceLocator()->get('Manage/CompanyEntity');           
$postData = $this->getRequest()->getPost()->toArray();           
$companyEntity->exchangeArray($postData);           
$companyForm->bind($companyEntity);            if($companyForm->isValid(){      
               
....            }
Currently this code give a solution to be but still I need to know why the
bind approach don't work
            $companyForm = new \Manage\Forms\CompanyForm();           
$companyEntity = $this->getServiceLocator()->get('Manage/CompanyEntity');       
    
$postData = $this->getRequest()->getPost()->toArray();           
$companyEntity->exchangeArray($postData);           
$companyForm->setInputFilter($companyEntity->getInputFilter());           
$companyForm->setData($postData);            if ($companyForm->isValid()) {     
          
....            }
Am I am doing it right? Any suggestion would be much helpful

Regards
Rajamohan




--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Form-Bind-Object-Issue-tp4658581.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to