_getDefaults(), $defaults); $eBelongTo = null; if ($this->isArray()) { $eBelongTo = $this->getElementsBelongTo(); $defaults = $this->_dissolveArrayValue($defaults, $eBelongTo); } foreach ($this->getElements() as $name => $element) { $check = $defaults; if (($belongsTo = $element->getBelongsTo()) !== $eBelongTo) { $check = $this->_dissolveArrayValue($defaults, $belongsTo); } if (array_key_exists($name, $check)) { $this->setDefault($name, $check[$name]); $defaults = $this->_dissolveArrayUnsetKey($defaults, $belongsTo, $name); } } foreach ($this->getSubForms() as $name => $form) { // Give SubForm its local defaults instead of global defaults $form->setDefaults(Qs_Array::get($defaults, $name, [])); } return $this; } public function isValid($data) { if (!is_array($data)) { require_once 'Zend/Form/Exception.php'; throw new Zend_Form_Exception(__METHOD__ . ' expects an array'); } $translator = $this->getTranslator(); $valid = true; $eBelongTo = null; $formData = $data; if ($this->isArray()) { $eBelongTo = $this->getElementsBelongTo(); $data = $this->_dissolveArrayValue($data, $eBelongTo); } $context = $data; foreach ($this->getElements() as $key => $element) { if (null !== $translator && $this->hasTranslator() && !$element->hasTranslator()) { $element->setTranslator($translator); } $check = $data; if (($belongsTo = $element->getBelongsTo()) !== $eBelongTo) { $check = $this->_dissolveArrayValue($data, $belongsTo); } if (!isset($check[$key])) { $valid = $element->isValid(null, $context) && $valid; } else { $valid = $element->isValid($check[$key], $context) && $valid; $data = $this->_dissolveArrayUnsetKey($data, $belongsTo, $key); } } foreach ($this->getSubForms() as $key => $form) { if (null !== $translator && $this->hasTranslator() && !$form->hasTranslator()) { $form->setTranslator($translator); } $valid = $form->isValid(Qs_Array::get($formData, $key, [])) && $valid; } $this->_errorsExist = !$valid; // If manually flagged as an error, return invalid status if ($this->_errorsForced) { return false; } return $valid; } public function isValidPartial(array $data) { $formData = $data; $eBelongTo = null; if ($this->isArray()) { $eBelongTo = $this->getElementsBelongTo(); $data = $this->_dissolveArrayValue($data, $eBelongTo); } $translator = $this->getTranslator(); $valid = true; $context = $data; foreach ($this->getElements() as $key => $element) { $check = $data; if (($belongsTo = $element->getBelongsTo()) !== $eBelongTo) { $check = $this->_dissolveArrayValue($data, $belongsTo); } if (isset($check[$key])) { if (null !== $translator && !$element->hasTranslator()) { $element->setTranslator($translator); } $valid = $element->isValid($check[$key], $context) && $valid; $data = $this->_dissolveArrayUnsetKey($data, $belongsTo, $key); } } foreach ($this->getSubForms() as $key => $form) { if (null !== $translator && !$form->hasTranslator()) { $form->setTranslator($translator); } $valid = $form->isValidPartial(Qs_Array::get($formData, $key, [])) && $valid; } $this->_errorsExist = !$valid; return $valid; } }