Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZendFramework][ZF] Formularz
Forum PHP.pl > Forum > PHP > Frameworki
Ghost_78
Witam serdecznie smile.gif
Mecze sie z jednym problemem od kilku dni i moze tu znajde pomoc:)
Wiec tak. Tworze sobie klase formularza
  1. class My_Form_AddClient extends Zend_Form{
  2. public $elementDecorators = array(
  3. 'ViewHelper',
  4. 'Errors',
  5. array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
  6. array('Label', array('tag' => 'td', 'class' => 'lbl')),
  7. array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
  8. );
  9.  
  10. public $buttonDecorators = array(
  11. 'ViewHelper',
  12. array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
  13. array(array('label' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'prepend')),
  14. array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
  15. );
  16.  
  17. public function init(){
  18. $this->_build();
  19. $this->_setupDefaults();
  20. my_print_r($this->getMessages());
  21. }
  22.  
  23. protected function _build(){
  24. $this->addElement('text', 'firmname', array(
  25. 'decorators' => $this->elementDecorators,
  26. 'label' => 'Nazwa firmy:',
  27. 'required' => true,
  28. 'filters' => array('StringTrim'),
  29. 'validators' => array(
  30. array('StringLength', false, array(2)))
  31. )
  32. );
  33. $this->addElement('text', 'firstname', array(
  34. 'decorators' => $this->elementDecorators,
  35. 'label' => 'First Name:')
  36. );
  37. $this->addElement('text', 'lastname', array(
  38. 'decorators' => $this->elementDecorators,
  39. 'label' => 'Last Name:')
  40. );
  41. $this->addElement('submit', 'save', array(
  42. 'decorators' => $this->buttonDecorators,
  43. 'label' => 'Save')
  44. );
  45. }
  46.  
  47. protected function _setupDefaults(){
  48. $controller = Zend_Controller_Front::getInstance();
  49. $this->setDefaults(array('firmname'=>$controller->getRequest()->getParam('firmname')));
  50. }
  51.  
  52. public function loadDefaultDecorators(){
  53. $this->setDecorators(array(
  54. 'FormElements',
  55. array('HtmlTag', array('tag' => 'table','class'=>'form')),
  56. 'Form',
  57. ));
  58. }


i teraz - mam problem z tym aby zmienic styl ramki odpowiedniego pola w przypadku kiedy byla podana zla wartosc. Tzn ta ktora nie przeszla validacji. Czy jest to do zrobienia w ZF w miare przystepny sposob ?

Pozdrawiam
quality
Style błędów mozna rowniez ustawic w decoratorach:

  1. public $decoratorsClear = array (
  2. 'ViewHelper',
  3. array('Errors', array('class'=>'error'))
  4. );


To był najprostszy sposob. Mozna jednak pobrac osobno bledy i je przetworzyc po swojemu. Ja tak robie przy formularzach ajaxowych.
Sa takie metody jak "getErrors()", getErrorMessages()" - nie pamietam czy dokladnie takie nazwy. poczytaj w dokumentacji.

Pozdrawiam
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.