Posted By

jiewmeng on 07/26/10


Tagged

zend-framework


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

osirisinternet
capuleto


Custom Zend_Form: Changed Decorators & added methods


 / Published in: PHP
 

2 main objectives:

  • change default decorators of element and form
  • setValues() mainly used for persisting form entry from request params across requests
  1. class Application_Form_Abstract extends Zend_Form {
  2. function loadDefaultDecorators() {
  3. if ($this->loadDefaultDecoratorsIsDisabled()) {
  4. return $this;
  5. }
  6.  
  7. // for elements
  8. $decorators = $this->_elementDecorators;
  9. if (empty($decorators)) {
  10. $this->setElementDecorators(array(
  11. 'ViewHelper',
  12. 'Errors',
  13. array('Description', array('tag' => 'p')),
  14. 'Label',
  15. array('HtmlTag', array('tag' => 'p'))
  16. ));
  17. $this->getElement('submit')->removeDecorator('Label');
  18. }
  19.  
  20. // for form
  21. $decorators = $this->getDecorators();
  22. if (empty($decorators)) {
  23. $this->addDecorator('FormElements')
  24. ->addDecorator('Description', array('placement' => 'PREPEND', 'tag' => 'p'))
  25. ->addDecorator('Form');
  26. }
  27. return $this;
  28. }
  29. function setValue($element, $value) {
  30. $this->getElement($element)->setValue($value);
  31. }
  32. function setValues($values) {
  33. foreach ($this->getElements() as $elem) {
  34. if (!$elem->getIgnore() && array_key_exists($elem->getName(), $values)) {
  35. $elem->setValue($values[$elem->getName()]);
  36. }
  37. }
  38. }
  39. }

Report this snippet  

You need to login to post a comment.