Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ZendFramework][ZF] Formularz
Ghost_78
post
Post #1





Grupa: Zarejestrowani
Postów: 222
Pomógł: 34
Dołączył: 3.11.2010

Ostrzeżenie: (0%)
-----


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


--------------------
Always look on the bright side of life ;-)
Go to the top of the page
+Quote Post
quality
post
Post #2





Grupa: Zarejestrowani
Postów: 172
Pomógł: 9
Dołączył: 13.02.2006
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


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


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 05:24