12 * obtain it through the world-wide-web, please send an email |
12 * obtain it through the world-wide-web, please send an email |
13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Form |
16 * @package Zend_Form |
17 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
17 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
18 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 */ |
19 */ |
20 |
20 |
21 /** @see Zend_Validate_Interface */ |
21 /** @see Zend_Validate_Interface */ |
22 require_once 'Zend/Validate/Interface.php'; |
22 require_once 'Zend/Validate/Interface.php'; |
24 /** |
24 /** |
25 * Zend_Form |
25 * Zend_Form |
26 * |
26 * |
27 * @category Zend |
27 * @category Zend |
28 * @package Zend_Form |
28 * @package Zend_Form |
29 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
29 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) |
30 * @license http://framework.zend.com/license/new-bsd New BSD License |
30 * @license http://framework.zend.com/license/new-bsd New BSD License |
31 * @version $Id: Form.php 25223 2013-01-17 14:44:54Z frosch $ |
31 * @version $Id$ |
32 */ |
32 */ |
33 class Zend_Form implements Iterator, Countable, Zend_Validate_Interface |
33 class Zend_Form implements Iterator, Countable, Zend_Validate_Interface |
34 { |
34 { |
35 /**#@+ |
35 /**#@+ |
36 * Plugin loader type constants |
36 * Plugin loader type constants |
224 * Constructor |
224 * Constructor |
225 * |
225 * |
226 * Registers form view helper as decorator |
226 * Registers form view helper as decorator |
227 * |
227 * |
228 * @param mixed $options |
228 * @param mixed $options |
229 * @return void |
|
230 */ |
229 */ |
231 public function __construct($options = null) |
230 public function __construct($options = null) |
232 { |
231 { |
233 if (is_array($options)) { |
232 if (is_array($options)) { |
234 $this->setOptions($options); |
233 $this->setOptions($options); |
261 } |
260 } |
262 $this->setSubForms($subForms); |
261 $this->setSubForms($subForms); |
263 |
262 |
264 $displayGroups = array(); |
263 $displayGroups = array(); |
265 foreach ($this->_displayGroups as $group) { |
264 foreach ($this->_displayGroups as $group) { |
|
265 /** @var Zend_Form_DisplayGroup $clone */ |
266 $clone = clone $group; |
266 $clone = clone $group; |
267 $elements = array(); |
267 $elements = array(); |
268 foreach ($clone->getElements() as $name => $e) { |
268 foreach ($clone->getElements() as $name => $e) { |
269 $elements[] = $this->getElement($name); |
269 $elements[] = $this->getElement($name); |
270 } |
270 } |
279 * |
279 * |
280 * @return Zend_Form |
280 * @return Zend_Form |
281 */ |
281 */ |
282 public function reset() |
282 public function reset() |
283 { |
283 { |
|
284 /** @var Zend_Form_Element $element */ |
284 foreach ($this->getElements() as $element) { |
285 foreach ($this->getElements() as $element) { |
285 $element->setValue(null); |
286 $element->setValue(null); |
286 } |
287 } |
|
288 /** @var Zend_Form_SubForm $subForm */ |
287 foreach ($this->getSubForms() as $subForm) { |
289 foreach ($this->getSubForms() as $subForm) { |
288 $subForm->reset(); |
290 $subForm->reset(); |
289 } |
291 } |
290 |
292 |
291 return $this; |
293 return $this; |
437 * If a plugin loader does not exist for the given type, defaults are |
439 * If a plugin loader does not exist for the given type, defaults are |
438 * created. |
440 * created. |
439 * |
441 * |
440 * @param string $type |
442 * @param string $type |
441 * @return Zend_Loader_PluginLoader_Interface |
443 * @return Zend_Loader_PluginLoader_Interface |
|
444 * @throws Zend_Form_Exception |
442 */ |
445 */ |
443 public function getPluginLoader($type = null) |
446 public function getPluginLoader($type = null) |
444 { |
447 { |
445 $type = strtoupper($type); |
448 $type = strtoupper($type); |
446 if (!isset($this->_loaders[$type])) { |
449 if (!isset($this->_loaders[$type])) { |
561 'prefix' => $prefix, |
564 'prefix' => $prefix, |
562 'path' => $path, |
565 'path' => $path, |
563 'type' => $type, |
566 'type' => $type, |
564 ); |
567 ); |
565 |
568 |
|
569 /** @var Zend_Form_Element $element */ |
566 foreach ($this->getElements() as $element) { |
570 foreach ($this->getElements() as $element) { |
567 $element->addPrefixPath($prefix, $path, $type); |
571 $element->addPrefixPath($prefix, $path, $type); |
568 } |
572 } |
569 |
573 |
|
574 /** @var Zend_Form_SubForm $subForm */ |
570 foreach ($this->getSubForms() as $subForm) { |
575 foreach ($this->getSubForms() as $subForm) { |
571 $subForm->addElementPrefixPath($prefix, $path, $type); |
576 $subForm->addElementPrefixPath($prefix, $path, $type); |
572 } |
577 } |
573 |
578 |
574 return $this; |
579 return $this; |
1072 * Acts as a factory for creating elements. Elements created with this |
1080 * Acts as a factory for creating elements. Elements created with this |
1073 * method will not be attached to the form, but will contain element |
1081 * method will not be attached to the form, but will contain element |
1074 * settings as specified in the form object (including plugin loader |
1082 * settings as specified in the form object (including plugin loader |
1075 * prefix paths, default decorators, etc.). |
1083 * prefix paths, default decorators, etc.). |
1076 * |
1084 * |
1077 * @param string $type |
1085 * @param string $type |
1078 * @param string $name |
1086 * @param string $name |
1079 * @param array|Zend_Config $options |
1087 * @param array|Zend_Config $options |
|
1088 * @throws Zend_Form_Exception |
1080 * @return Zend_Form_Element |
1089 * @return Zend_Form_Element |
1081 */ |
1090 */ |
1082 public function createElement($type, $name, $options = null) |
1091 public function createElement($type, $name, $options = null) |
1083 { |
1092 { |
1084 if (!is_string($type)) { |
1093 if (!is_string($type)) { |
1232 unset($this->_elements[$name]); |
1241 unset($this->_elements[$name]); |
1233 if (array_key_exists($name, $this->_order)) { |
1242 if (array_key_exists($name, $this->_order)) { |
1234 unset($this->_order[$name]); |
1243 unset($this->_order[$name]); |
1235 $this->_orderUpdated = true; |
1244 $this->_orderUpdated = true; |
1236 } else { |
1245 } else { |
|
1246 /** @var Zend_Form_DisplayGroup $group */ |
1237 foreach ($this->_displayGroups as $group) { |
1247 foreach ($this->_displayGroups as $group) { |
1238 if (null !== $group->getElement($name)) { |
1248 if (null !== $group->getElement($name)) { |
1239 $group->removeElement($name); |
1249 $group->removeElement($name); |
1240 } |
1250 } |
1241 } |
1251 } |
1277 |
1287 |
1278 if ($this->isArray()) { |
1288 if ($this->isArray()) { |
1279 $eBelongTo = $this->getElementsBelongTo(); |
1289 $eBelongTo = $this->getElementsBelongTo(); |
1280 $defaults = $this->_dissolveArrayValue($defaults, $eBelongTo); |
1290 $defaults = $this->_dissolveArrayValue($defaults, $eBelongTo); |
1281 } |
1291 } |
|
1292 /** @var Zend_Form_Element $element */ |
1282 foreach ($this->getElements() as $name => $element) { |
1293 foreach ($this->getElements() as $name => $element) { |
1283 $check = $defaults; |
1294 $check = $defaults; |
1284 if (($belongsTo = $element->getBelongsTo()) !== $eBelongTo) { |
1295 if (($belongsTo = $element->getBelongsTo()) !== $eBelongTo) { |
1285 $check = $this->_dissolveArrayValue($defaults, $belongsTo); |
1296 $check = $this->_dissolveArrayValue($defaults, $belongsTo); |
1286 } |
1297 } |
1287 if (array_key_exists($name, $check)) { |
1298 if (array_key_exists($name, $check)) { |
1288 $this->setDefault($name, $check[$name]); |
1299 $this->setDefault($name, $check[$name]); |
1289 $defaults = $this->_dissolveArrayUnsetKey($defaults, $belongsTo, $name); |
1300 $defaults = $this->_dissolveArrayUnsetKey($defaults, $belongsTo, $name); |
1290 } |
1301 } |
1291 } |
1302 } |
|
1303 /** @var Zend_Form_SubForm $form */ |
1292 foreach ($this->getSubForms() as $name => $form) { |
1304 foreach ($this->getSubForms() as $name => $form) { |
1293 if (!$form->isArray() && array_key_exists($name, $defaults)) { |
1305 if (!$form->isArray() && array_key_exists($name, $defaults)) { |
1294 $form->setDefaults($defaults[$name]); |
1306 $form->setDefaults($defaults[$name]); |
1295 } else { |
1307 } else { |
1296 $form->setDefaults($defaults); |
1308 $form->setDefaults($defaults); |
1311 $name = (string) $name; |
1323 $name = (string) $name; |
1312 if ($element = $this->getElement($name)) { |
1324 if ($element = $this->getElement($name)) { |
1313 $element->setValue($value); |
1325 $element->setValue($value); |
1314 } else { |
1326 } else { |
1315 if (is_scalar($value)) { |
1327 if (is_scalar($value)) { |
|
1328 /** @var Zend_Form_SubForm $subForm */ |
1316 foreach ($this->getSubForms() as $subForm) { |
1329 foreach ($this->getSubForms() as $subForm) { |
1317 $subForm->setDefault($name, $value); |
1330 $subForm->setDefault($name, $value); |
1318 } |
1331 } |
1319 } elseif (is_array($value) && ($subForm = $this->getSubForm($name))) { |
1332 } elseif (is_array($value) && ($subForm = $this->getSubForm($name))) { |
1320 $subForm->setDefaults($value); |
1333 $subForm->setDefaults($value); |
1337 |
1350 |
1338 if ($subForm = $this->getSubForm($name)) { |
1351 if ($subForm = $this->getSubForm($name)) { |
1339 return $subForm->getValues(true); |
1352 return $subForm->getValues(true); |
1340 } |
1353 } |
1341 |
1354 |
|
1355 /** @var Zend_Form_SubForm $subForm */ |
1342 foreach ($this->getSubForms() as $subForm) { |
1356 foreach ($this->getSubForms() as $subForm) { |
1343 if ($name == $subForm->getElementsBelongTo()) { |
1357 if ($name == $subForm->getElementsBelongTo()) { |
1344 return $subForm->getValues(true); |
1358 return $subForm->getValues(true); |
1345 } |
1359 } |
1346 } |
1360 } |
1359 $eBelongTo = null; |
1373 $eBelongTo = null; |
1360 |
1374 |
1361 if ($this->isArray()) { |
1375 if ($this->isArray()) { |
1362 $eBelongTo = $this->getElementsBelongTo(); |
1376 $eBelongTo = $this->getElementsBelongTo(); |
1363 } |
1377 } |
1364 |
1378 /** @var Zend_Form_Element $element */ |
1365 foreach ($this->getElements() as $key => $element) { |
1379 foreach ($this->getElements() as $key => $element) { |
1366 if (!$element->getIgnore()) { |
1380 if (!$element->getIgnore()) { |
1367 $merge = array(); |
1381 $merge = array(); |
1368 if (($belongsTo = $element->getBelongsTo()) !== $eBelongTo) { |
1382 if (($belongsTo = $element->getBelongsTo()) !== $eBelongTo) { |
1369 if ('' !== (string)$belongsTo) { |
1383 if ('' !== (string)$belongsTo) { |
1372 } |
1386 } |
1373 $merge = $this->_attachToArray($element->getValue(), $key); |
1387 $merge = $this->_attachToArray($element->getValue(), $key); |
1374 $values = $this->_array_replace_recursive($values, $merge); |
1388 $values = $this->_array_replace_recursive($values, $merge); |
1375 } |
1389 } |
1376 } |
1390 } |
|
1391 /** @var Zend_Form_SubForm $subForm */ |
1377 foreach ($this->getSubForms() as $key => $subForm) { |
1392 foreach ($this->getSubForms() as $key => $subForm) { |
1378 $merge = array(); |
1393 $merge = array(); |
1379 if (!$subForm->isArray()) { |
1394 if (!$subForm->isArray()) { |
1380 $merge[$key] = $subForm->getValues(); |
1395 $merge[$key] = $subForm->getValues(); |
1381 } else { |
1396 } else { |
1413 if ($this->isArray()) { |
1428 if ($this->isArray()) { |
1414 $eBelongTo = $this->getElementsBelongTo(); |
1429 $eBelongTo = $this->getElementsBelongTo(); |
1415 $data = $this->_dissolveArrayValue($data, $eBelongTo); |
1430 $data = $this->_dissolveArrayValue($data, $eBelongTo); |
1416 } |
1431 } |
1417 $context = $data; |
1432 $context = $data; |
|
1433 /** @var Zend_Form_Element $element */ |
1418 foreach ($this->getElements() as $key => $element) { |
1434 foreach ($this->getElements() as $key => $element) { |
1419 if (!$element->getIgnore()) { |
1435 if (!$element->getIgnore()) { |
1420 $check = $data; |
1436 $check = $data; |
1421 if (($belongsTo = $element->getBelongsTo()) !== $eBelongTo) { |
1437 if (($belongsTo = $element->getBelongsTo()) !== $eBelongTo) { |
1422 $check = $this->_dissolveArrayValue($data, $belongsTo); |
1438 $check = $this->_dissolveArrayValue($data, $belongsTo); |
1432 } |
1448 } |
1433 $data = $this->_dissolveArrayUnsetKey($data, $belongsTo, $key); |
1449 $data = $this->_dissolveArrayUnsetKey($data, $belongsTo, $key); |
1434 } |
1450 } |
1435 } |
1451 } |
1436 } |
1452 } |
|
1453 /** @var Zend_Form_SubForm $form */ |
1437 foreach ($this->getSubForms() as $key => $form) { |
1454 foreach ($this->getSubForms() as $key => $form) { |
1438 $merge = array(); |
1455 $merge = array(); |
1439 if (isset($data[$key]) && !$form->isArray()) { |
1456 if (isset($data[$key]) && !$form->isArray()) { |
1440 $tmp = $form->getValidValues($data[$key]); |
1457 $tmp = $form->getValidValues($data[$key]); |
1441 if (!empty($tmp)) { |
1458 if (!empty($tmp)) { |
1543 if (null === $array) { |
1562 if (null === $array) { |
1544 return; |
1563 return; |
1545 } |
1564 } |
1546 |
1565 |
1547 if (null === $name) { |
1566 if (null === $name) { |
|
1567 /** @var Zend_Form_Element $element */ |
1548 foreach ($this->getElements() as $element) { |
1568 foreach ($this->getElements() as $element) { |
1549 $element->setBelongsTo($array); |
1569 $element->setBelongsTo($array); |
1550 } |
1570 } |
1551 } else { |
1571 } else { |
1552 if (null !== ($element = $this->getElement($name))) { |
1572 if (null !== ($element = $this->getElement($name))) { |
1604 * @return Zend_Form |
1624 * @return Zend_Form |
1605 */ |
1625 */ |
1606 public function addSubForm(Zend_Form $form, $name, $order = null) |
1626 public function addSubForm(Zend_Form $form, $name, $order = null) |
1607 { |
1627 { |
1608 $name = (string) $name; |
1628 $name = (string) $name; |
|
1629 /** @var Zend_Loader_PluginLoader $loader */ |
1609 foreach ($this->_loaders as $type => $loader) { |
1630 foreach ($this->_loaders as $type => $loader) { |
1610 $loaderPaths = $loader->getPaths(); |
1631 $loaderPaths = $loader->getPaths(); |
1611 foreach ($loaderPaths as $prefix => $paths) { |
1632 foreach ($loaderPaths as $prefix => $paths) { |
1612 foreach ($paths as $path) { |
1633 foreach ($paths as $path) { |
1613 $form->addPrefixPath($prefix, $path, $type); |
1634 $form->addPrefixPath($prefix, $path, $type); |
1866 |
1887 |
1867 /** |
1888 /** |
1868 * Add a display group object (used with cloning) |
1889 * Add a display group object (used with cloning) |
1869 * |
1890 * |
1870 * @param Zend_Form_DisplayGroup $group |
1891 * @param Zend_Form_DisplayGroup $group |
1871 * @param string|null $name |
1892 * @param string|null $name |
|
1893 * @throws Zend_Form_Exception |
1872 * @return Zend_Form |
1894 * @return Zend_Form |
1873 */ |
1895 */ |
1874 protected function _addDisplayGroupObject(Zend_Form_DisplayGroup $group, $name = null) |
1896 protected function _addDisplayGroupObject(Zend_Form_DisplayGroup $group, $name = null) |
1875 { |
1897 { |
1876 if (null === $name) { |
1898 if (null === $name) { |
1999 */ |
2021 */ |
2000 public function removeDisplayGroup($name) |
2022 public function removeDisplayGroup($name) |
2001 { |
2023 { |
2002 $name = (string) $name; |
2024 $name = (string) $name; |
2003 if (array_key_exists($name, $this->_displayGroups)) { |
2025 if (array_key_exists($name, $this->_displayGroups)) { |
|
2026 /** @var Zend_Form_Element $element */ |
2004 foreach ($this->_displayGroups[$name] as $key => $element) { |
2027 foreach ($this->_displayGroups[$name] as $key => $element) { |
2005 if (array_key_exists($key, $this->_elements)) { |
2028 if (array_key_exists($key, $this->_elements)) { |
2006 $this->_order[$key] = $element->getOrder(); |
2029 $this->_order[$key] = $element->getOrder(); |
2007 $this->_orderUpdated = true; |
2030 $this->_orderUpdated = true; |
2008 } |
2031 } |
2028 { |
2051 { |
2029 foreach ($this->_displayGroups as $key => $group) { |
2052 foreach ($this->_displayGroups as $key => $group) { |
2030 if (array_key_exists($key, $this->_order)) { |
2053 if (array_key_exists($key, $this->_order)) { |
2031 unset($this->_order[$key]); |
2054 unset($this->_order[$key]); |
2032 } |
2055 } |
|
2056 /** @var Zend_Form_Element $element */ |
2033 foreach ($group as $name => $element) { |
2057 foreach ($group as $name => $element) { |
2034 if (isset($this->_elements[$name])) { |
2058 if (isset($this->_elements[$name])) { |
2035 $this->_order[$name] = $element->getOrder(); |
2059 $this->_order[$name] = $element->getOrder(); |
2036 } |
2060 } |
2037 $this->_order[$name] = $element->getOrder(); |
2061 $this->_order[$name] = $element->getOrder(); |
2192 if ($this->$name instanceof Zend_Form_Element || |
2216 if ($this->$name instanceof Zend_Form_Element || |
2193 $this->$name instanceof Zend_Form) { |
2217 $this->$name instanceof Zend_Form) { |
2194 array_splice($ordered, $order, 0, array($this->$name)); |
2218 array_splice($ordered, $order, 0, array($this->$name)); |
2195 } else if ($this->$name instanceof Zend_Form_DisplayGroup) { |
2219 } else if ($this->$name instanceof Zend_Form_DisplayGroup) { |
2196 $subordered = array(); |
2220 $subordered = array(); |
|
2221 /** @var Zend_Form_Element $element */ |
2197 foreach ($this->$name->getElements() as $element) { |
2222 foreach ($this->$name->getElements() as $element) { |
2198 $suborder = $element->getOrder(); |
2223 $suborder = $element->getOrder(); |
2199 $suborder = (null !== $suborder) ? $suborder : count($subordered); |
2224 $suborder = (null !== $suborder) ? $suborder : count($subordered); |
2200 array_splice($subordered, $suborder, 0, array($element)); |
2225 array_splice($subordered, $suborder, 0, array($element)); |
2201 } |
2226 } |
2252 if ($this->isArray()) { |
2277 if ($this->isArray()) { |
2253 $eBelongTo = $this->getElementsBelongTo(); |
2278 $eBelongTo = $this->getElementsBelongTo(); |
2254 $data = $this->_dissolveArrayValue($data, $eBelongTo); |
2279 $data = $this->_dissolveArrayValue($data, $eBelongTo); |
2255 } |
2280 } |
2256 $context = $data; |
2281 $context = $data; |
|
2282 /** @var Zend_Form_Element $element */ |
2257 foreach ($this->getElements() as $key => $element) { |
2283 foreach ($this->getElements() as $key => $element) { |
2258 if (null !== $translator && $this->hasTranslator() |
2284 if (null !== $translator && $this->hasTranslator() |
2259 && !$element->hasTranslator()) { |
2285 && !$element->hasTranslator()) { |
2260 $element->setTranslator($translator); |
2286 $element->setTranslator($translator); |
2261 } |
2287 } |
2268 } else { |
2294 } else { |
2269 $valid = $element->isValid($check[$key], $context) && $valid; |
2295 $valid = $element->isValid($check[$key], $context) && $valid; |
2270 $data = $this->_dissolveArrayUnsetKey($data, $belongsTo, $key); |
2296 $data = $this->_dissolveArrayUnsetKey($data, $belongsTo, $key); |
2271 } |
2297 } |
2272 } |
2298 } |
|
2299 /** @var Zend_Form_SubForm $form */ |
2273 foreach ($this->getSubForms() as $key => $form) { |
2300 foreach ($this->getSubForms() as $key => $form) { |
2274 if (null !== $translator && $this->hasTranslator() |
2301 if (null !== $translator && $this->hasTranslator() |
2275 && !$form->hasTranslator()) { |
2302 && !$form->hasTranslator()) { |
2276 $form->setTranslator($translator); |
2303 $form->setTranslator($translator); |
2277 } |
2304 } |
2311 |
2338 |
2312 $translator = $this->getTranslator(); |
2339 $translator = $this->getTranslator(); |
2313 $valid = true; |
2340 $valid = true; |
2314 $context = $data; |
2341 $context = $data; |
2315 |
2342 |
|
2343 /** @var Zend_Form_Element $element */ |
2316 foreach ($this->getElements() as $key => $element) { |
2344 foreach ($this->getElements() as $key => $element) { |
2317 $check = $data; |
2345 $check = $data; |
2318 if (($belongsTo = $element->getBelongsTo()) !== $eBelongTo) { |
2346 if (($belongsTo = $element->getBelongsTo()) !== $eBelongTo) { |
2319 $check = $this->_dissolveArrayValue($data, $belongsTo); |
2347 $check = $this->_dissolveArrayValue($data, $belongsTo); |
2320 } |
2348 } |
2324 } |
2352 } |
2325 $valid = $element->isValid($check[$key], $context) && $valid; |
2353 $valid = $element->isValid($check[$key], $context) && $valid; |
2326 $data = $this->_dissolveArrayUnsetKey($data, $belongsTo, $key); |
2354 $data = $this->_dissolveArrayUnsetKey($data, $belongsTo, $key); |
2327 } |
2355 } |
2328 } |
2356 } |
|
2357 /** @var Zend_Form_SubForm $form */ |
2329 foreach ($this->getSubForms() as $key => $form) { |
2358 foreach ($this->getSubForms() as $key => $form) { |
2330 if (null !== $translator && !$form->hasTranslator()) { |
2359 if (null !== $translator && !$form->hasTranslator()) { |
2331 $form->setTranslator($translator); |
2360 $form->setTranslator($translator); |
2332 } |
2361 } |
2333 if (isset($data[$key]) && !$form->isArray()) { |
2362 if (isset($data[$key]) && !$form->isArray()) { |
2492 * |
2521 * |
2493 * @return bool |
2522 * @return bool |
2494 */ |
2523 */ |
2495 public function hasErrors() |
2524 public function hasErrors() |
2496 { |
2525 { |
2497 return $this->_errorsExist; |
2526 $errors = $this->_errorsExist; |
|
2527 |
|
2528 if (!$errors) { |
|
2529 /** @var Zend_Form_Element $element */ |
|
2530 foreach ($this->getElements() as $element) { |
|
2531 if ($element->hasErrors()) { |
|
2532 $errors = true; |
|
2533 break; |
|
2534 } |
|
2535 } |
|
2536 |
|
2537 /** @var Zend_Form_SubForm $subForm */ |
|
2538 foreach ($this->getSubForms() as $subForm) { |
|
2539 if ($subForm->hasErrors()) { |
|
2540 $errors = true; |
|
2541 break; |
|
2542 } |
|
2543 } |
|
2544 } |
|
2545 |
|
2546 return $errors; |
2498 } |
2547 } |
2499 |
2548 |
2500 /** |
2549 /** |
2501 * Get error codes for all elements failing validation |
2550 * Get error codes for all elements failing validation |
2502 * |
2551 * |
2503 * @param string $name |
2552 * @param string $name |
|
2553 * @param bool $suppressArrayNotation |
2504 * @return array |
2554 * @return array |
2505 */ |
2555 */ |
2506 public function getErrors($name = null, $suppressArrayNotation = false) |
2556 public function getErrors($name = null, $suppressArrayNotation = false) |
2507 { |
2557 { |
2508 $errors = array(); |
2558 $errors = array(); |
2512 } else if (isset($this->_subForms[$name])) { |
2562 } else if (isset($this->_subForms[$name])) { |
2513 return $this->getSubForm($name)->getErrors(null, true); |
2563 return $this->getSubForm($name)->getErrors(null, true); |
2514 } |
2564 } |
2515 } |
2565 } |
2516 |
2566 |
|
2567 /** @var Zend_Form_Element $element */ |
2517 foreach ($this->_elements as $key => $element) { |
2568 foreach ($this->_elements as $key => $element) { |
2518 $errors[$key] = $element->getErrors(); |
2569 $errors[$key] = $element->getErrors(); |
2519 } |
2570 } |
|
2571 /** @var Zend_Form_SubForm $subForm */ |
2520 foreach ($this->getSubForms() as $key => $subForm) { |
2572 foreach ($this->getSubForms() as $key => $subForm) { |
2521 $merge = array(); |
2573 $merge = array(); |
2522 if (!$subForm->isArray()) { |
2574 if (!$subForm->isArray()) { |
2523 $merge[$key] = $subForm->getErrors(); |
2575 $merge[$key] = $subForm->getErrors(); |
2524 } else { |
2576 } else { |
2550 if (isset($this->_elements[$name])) { |
2602 if (isset($this->_elements[$name])) { |
2551 return $this->getElement($name)->getMessages(); |
2603 return $this->getElement($name)->getMessages(); |
2552 } else if (isset($this->_subForms[$name])) { |
2604 } else if (isset($this->_subForms[$name])) { |
2553 return $this->getSubForm($name)->getMessages(null, true); |
2605 return $this->getSubForm($name)->getMessages(null, true); |
2554 } |
2606 } |
|
2607 /** @var Zend_Form_SubForm $subForm */ |
2555 foreach ($this->getSubForms() as $key => $subForm) { |
2608 foreach ($this->getSubForms() as $key => $subForm) { |
2556 if ($subForm->isArray()) { |
2609 if ($subForm->isArray()) { |
2557 $belongTo = $subForm->getElementsBelongTo(); |
2610 $belongTo = $subForm->getElementsBelongTo(); |
2558 if ($name == $this->_getArrayName($belongTo)) { |
2611 if ($name == $this->_getArrayName($belongTo)) { |
2559 return $subForm->getMessages(null, true); |
2612 return $subForm->getMessages(null, true); |
2567 return $customMessages; |
2620 return $customMessages; |
2568 } |
2621 } |
2569 |
2622 |
2570 $messages = array(); |
2623 $messages = array(); |
2571 |
2624 |
|
2625 /** @var Zend_Form_Element $element */ |
2572 foreach ($this->getElements() as $name => $element) { |
2626 foreach ($this->getElements() as $name => $element) { |
2573 $eMessages = $element->getMessages(); |
2627 $eMessages = $element->getMessages(); |
2574 if (!empty($eMessages)) { |
2628 if (!empty($eMessages)) { |
2575 $messages[$name] = $eMessages; |
2629 $messages[$name] = $eMessages; |
2576 } |
2630 } |
2577 } |
2631 } |
2578 |
2632 |
|
2633 /** @var Zend_Form_SubForm $subForm */ |
2579 foreach ($this->getSubForms() as $key => $subForm) { |
2634 foreach ($this->getSubForms() as $key => $subForm) { |
2580 $merge = $subForm->getMessages(null, true); |
2635 $merge = $subForm->getMessages(null, true); |
2581 if (!empty($merge)) { |
2636 if (!empty($merge)) { |
2582 if (!$subForm->isArray()) { |
2637 if (!$subForm->isArray()) { |
2583 $merge = array($key => $merge); |
2638 $merge = array($key => $merge); |
2663 |
2718 |
2664 /** |
2719 /** |
2665 * Add a decorator for rendering the element |
2720 * Add a decorator for rendering the element |
2666 * |
2721 * |
2667 * @param string|Zend_Form_Decorator_Interface $decorator |
2722 * @param string|Zend_Form_Decorator_Interface $decorator |
2668 * @param array|Zend_Config $options Options with which to initialize decorator |
2723 * @param array|Zend_Config $options Options with which to initialize decorator |
|
2724 * @throws Zend_Form_Exception |
2669 * @return Zend_Form |
2725 * @return Zend_Form |
2670 */ |
2726 */ |
2671 public function addDecorator($decorator, $options = null) |
2727 public function addDecorator($decorator, $options = null) |
2672 { |
2728 { |
2673 if ($decorator instanceof Zend_Form_Decorator_Interface) { |
2729 if ($decorator instanceof Zend_Form_Decorator_Interface) { |
2926 if (null !== $view) { |
2986 if (null !== $view) { |
2927 $this->setView($view); |
2987 $this->setView($view); |
2928 } |
2988 } |
2929 |
2989 |
2930 $content = ''; |
2990 $content = ''; |
|
2991 /** @var Zend_Form_Decorator_Abstract $decorator */ |
2931 foreach ($this->getDecorators() as $decorator) { |
2992 foreach ($this->getDecorators() as $decorator) { |
2932 $decorator->setElement($this); |
2993 $decorator->setElement($this); |
2933 $content = $decorator->render($content); |
2994 $content = $decorator->render($content); |
2934 } |
2995 } |
2935 $this->_setIsRendered(); |
2996 $this->_setIsRendered(); |
3355 $items[$index] = $key; |
3420 $items[$index] = $key; |
3356 ++$index; |
3421 ++$index; |
3357 } else { |
3422 } else { |
3358 $items[$order] = $key; |
3423 $items[$order] = $key; |
3359 } |
3424 } |
|
3425 } elseif (isset($items[$order]) && $items[$order] !== $key) { |
|
3426 throw new Zend_Form_Exception('Form elements ' . |
|
3427 $items[$order] . ' and ' . $key . |
|
3428 ' have the same order (' . |
|
3429 $order . ') - ' . |
|
3430 'this would result in only the last added element to be rendered' |
|
3431 ); |
3360 } else { |
3432 } else { |
3361 $items[$order] = $key; |
3433 $items[$order] = $key; |
3362 } |
3434 } |
3363 } |
3435 } |
3364 |
3436 |