bind() public method

Binds POST data to the field, transforms and validates it.
public bind ( string | array $taintedData ) : boolean
$taintedData string | array The POST data
return boolean Whether the form is valid
Beispiel #1
0
 /**
  * {@inheritDoc}
  */
 public function bind($data)
 {
     if ($this->mode === self::GROUP) {
         parent::bind($data);
     } else {
         Field::bind($data);
     }
 }
Beispiel #2
0
 /**
  * Binds POST data to the field, transforms and validates it.
  *
  * @param  string|array $taintedData  The POST data
  * @return boolean                    Whether the form is valid
  */
 public function bind($taintedData)
 {
     if (null === $taintedData) {
         $taintedData = array();
     }
     if (!is_array($taintedData)) {
         throw new UnexpectedTypeException($taintedData, 'array');
     }
     foreach ($this->fields as $key => $field) {
         if (!isset($taintedData[$key])) {
             $taintedData[$key] = null;
         }
     }
     $taintedData = $this->preprocessData($taintedData);
     foreach ($taintedData as $key => $value) {
         if ($this->has($key)) {
             $this->fields[$key]->bind($value);
         }
     }
     $data = $this->getTransformedData();
     $this->updateObject($data);
     // bind and reverse transform the data
     parent::bind($data);
     $this->extraFields = array();
     foreach ($taintedData as $key => $value) {
         if (!$this->has($key)) {
             $this->extraFields[] = $key;
         }
     }
 }
Beispiel #3
0
 /**
  * Binds POST data to the field, transforms and validates it.
  *
  * @param  string|array $taintedData  The POST data
  * @return boolean                    Whether the form is valid
  */
 public function bind($taintedData)
 {
     if ($taintedData === null) {
         $taintedData = array();
     }
     if (!is_array($taintedData)) {
         throw new UnexpectedTypeException('You must pass an array parameter to the bind() method');
     }
     foreach ($this->fields as $key => $field) {
         if (!isset($taintedData[$key])) {
             $taintedData[$key] = null;
         }
     }
     foreach ($taintedData as $key => $value) {
         if ($this->has($key)) {
             $this->fields[$key]->bind($value);
         }
     }
     $data = $this->getTransformedData();
     $iterator = new RecursiveFieldsWithPropertyPathIterator($this);
     $iterator = new \RecursiveIteratorIterator($iterator);
     foreach ($iterator as $field) {
         $field->updateObject($data);
     }
     // bind and reverse transform the data
     parent::bind($data);
     $this->extraFields = array();
     foreach ($taintedData as $key => $value) {
         if (!$this->has($key)) {
             $this->extraFields[] = $key;
         }
     }
 }