Modified:
branches/FreeForm/Solar/Form.php
branches/Solar_Form/Solar/Form.php
Log:
Fixed validate() to not use references to element data: was causing
a "Indirect modification of overloaded element of Solar_Form_Element..."
Modified: branches/FreeForm/Solar/Form.php
==============================================================================
--- branches/FreeForm/Solar/Form.php (original)
+++ branches/FreeForm/Solar/Form.php Sun Oct 5 10:33:19 2008
@@ -224,17 +224,24 @@
*
* @param string $array Rename the element as a key in this array.
*
+ * @param bool $throw If true, throws an exception if the element is
not
+ * found.
+ *
* @return Solar_Form_Element
*
*/
- public function getElement($name, $array = null)
+ public function getElement($name, $array = null, $throw = false)
{
$name = $this->_prepareName($name, $array);
-
+
if (empty($this->elements[$name])) {
- throw $this->_exception('ERR_NO_SUCH_ELEMENT', array(
- 'name' => $name,
- ));
+ if ($throw) {
+ throw $this->_exception('ERR_NO_SUCH_ELEMENT', array(
+ 'name' => $name,
+ ));
+ } else {
+ return false;
+ }
}
return $this->elements[$name];
@@ -333,7 +340,9 @@
*/
public function setAttribs($name, $attribs, $array = null)
{
- $this->getElement($name, $array)->setAttribs($attribs);
+ if ($elem = $this->getElement($name, $array)) {
+ $elem->setAttribs($attribs);
+ }
}
/**
@@ -351,7 +360,9 @@
*/
public function setType($name, $type, $array = null)
{
- $this->getElement($name, $array)->setType($type);
+ if ($elem = $this->getElement($name, $array)) {
+ $elem->setType($type);
+ }
}
/**
@@ -415,7 +426,9 @@
*/
public function addFilter($name, $spec, $array = null)
{
- $this->getElement($name, $array)->addFilter($spec);
+ if ($elem = $this->getElement($name, $array)) {
+ $elem->addFilter($spec);
+ }
}
/**
@@ -454,8 +467,10 @@
*/
public function addInvalid($name, $spec, $array = null)
{
- $this->getElement($name, $array)->addInvalid($spec);
- $this->_status = false;
+ if ($elem = $this->getElement($name, $array)) {
+ $elem->addInvalid($spec);
+ $this->_status = false;
+ }
}
/**
@@ -503,7 +518,9 @@
*/
public function setValue($name, $value, $array = null)
{
- $this->getElement($name, $array)->setValue($value);
+ if ($elem = $this->getElement($name, $array)) {
+ $elem->setValue($value);
+ }
}
/**
@@ -607,18 +624,23 @@
// loop uses an info **reference**, not a copy.
$data = array();
foreach ($this->elements as $name => $elem) {
- // keep a **reference** to the data (not a copy)
- $data[$name] =& $elem['value'];
+ // keep a **copy** of the data (not a reference)
+ $data[$name] = $elem->value;
// set the filters and require-flag, reference not needed
- $this->_filter->addChainFilters($name, $elem['filters']);
- $this->_filter->setChainRequire($name, $elem['require']);
+ $this->_filter->addChainFilters($name, $elem->filters);
+ $this->_filter->setChainRequire($name, $elem->require);
}
- // apply the filter chain to the data, which will modify the
- // element data in place because of the references
+ // apply the filter chain to the data, which will modify the
+ // element data in place because of the reference
$this->_status = $this->_filter->applyChain($data);
+
+ // put the filtered values back to the elements
+ foreach ($data as $name => $value) {
+ $this->elements[$name]->setValue($value);
+ }
// set the main feedback message
if ($this->_status) {
Modified: branches/Solar_Form/Solar/Form.php
==============================================================================
--- branches/Solar_Form/Solar/Form.php (original)
+++ branches/Solar_Form/Solar/Form.php Sun Oct 5 10:33:19 2008
@@ -624,18 +624,23 @@
// loop uses an info **reference**, not a copy.
$data = array();
foreach ($this->elements as $name => $elem) {
- // keep a **reference** to the data (not a copy)
- $data[$name] =& $elem['value'];
+ // keep a **copy** of the data (not a reference)
+ $data[$name] = $elem->value;
// set the filters and require-flag, reference not needed
- $this->_filter->addChainFilters($name, $elem['filters']);
- $this->_filter->setChainRequire($name, $elem['require']);
+ $this->_filter->addChainFilters($name, $elem->filters);
+ $this->_filter->setChainRequire($name, $elem->require);
}
- // apply the filter chain to the data, which will modify the
- // element data in place because of the references
+ // apply the filter chain to the data, which will modify the
+ // element data in place because of the reference
$this->_status = $this->_filter->applyChain($data);
+
+ // put the filtered values back to the elements
+ foreach ($data as $name => $value) {
+ $this->elements[$name]->setValue($value);
+ }
// set the main feedback message
if ($this->_status) {