Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ZendFramework] Zamiana zrenderowanego formualrza na tablicę
padalec83
post
Post #1





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 9.02.2006

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


Witam,
poszukuję jakiejś szybkiej metody na całkowite usunięcie domyślnego decorataroa z Zend_Form i zamianę na tablicę asocjacyjną. Jak na razie udało mi się zrobić coś takiego:
  1. public function renderToArray(){
  2. $this->setDisableLoadDefaultDecorators( false );
  3. $aFormArray['method'] = $this->getMethod();
  4. $aFormArray['action'] = $this->getAction();
  5. $aFormArray['enctype'] = $this->getEnctype();
  6.  
  7. $i=0;
  8. foreach ($this->getElements() as $sKey => $oElement) {
  9. $aFormArray['elements'][$i]['label'] = $oElement->getLabel();
  10. $aFormArray['elements'][$i]['name'] = $oElement->getName();
  11. $i++;
  12. }
  13.  
  14. return $aFormArray;
  15. }

nie wiem której metody trzeba użyć aby dostać dany element w postaci htmla a mianowicie np jak mamy element text czyli <input type="text" id="" /> itd.

Pozdrawiam


--------------------
www.silversite.pl
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
tvister
post
Post #2





Grupa: Zarejestrowani
Postów: 253
Pomógł: 29
Dołączył: 18.08.2008

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


Prosta sprawa musisz wyrzucić wszystkie dekoratory dla elementu oprócz 'Zend_Form_Decorator_ViewHelper'.
..no i zrenderować.

Ten post edytował tvister 31.05.2011, 13:32:54


--------------------
Kto rano wstaje ten leje jak z cebra.
Go to the top of the page
+Quote Post
padalec83
post
Post #3





Grupa: Zarejestrowani
Postów: 18
Pomógł: 0
Dołączył: 9.02.2006

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


zrobiłem coś takiego:
  1. public function renderToArray(){
  2. $this->setDisableLoadDefaultDecorators(true);
  3. $aFormArray = array();
  4. $this->render(new Zend_View());
  5. $aFormArray['method'] = $this->getMethod();
  6. $aFormArray['action'] = $this->getAction();
  7. $aFormArray['enctype'] = $this->getEnctype();
  8. $aFormArray['errors'] = $this->getErrors();
  9.  
  10. $i=0;
  11. foreach ($this->getElements() as $sKey => $oElement) {
  12. $aFormArray['elements'][$i]['label'] = $oElement->getLabel();
  13. $aFormArray['elements'][$i]['name'] = $oElement->getName();
  14. $aFormArray['elements'][$i]['id'] = $oElement->getId();
  15. $aFormArray['elements'][$i]['required'] = $oElement->isRequired();
  16. $aFormArray['elements'][$i]['description'] = $oElement->getDescription();
  17. $aFormArray['elements'][$i]['type'] = strtolower(substr( $oElement->getType(), strrpos($oElement->getType(),'_')+1 , strrpos($oElement->getType(),'_')));
  18. $aFormArray['elements'][$i]['html'] = $oElement->renderViewHelper();
  19. $aFormArray['elements'][$i]['value'] = $oElement->getValue();
  20. $i++;
  21. }
  22.  
  23. return $aFormArray;
  24. }



Teraz mam problem z metodą isValid(), ponieważ jak tylko wchodzę na stronę jeszcze nie klikam submita, a od razu pokazują mi się błędy o nie wprowadzeniu wymaganych pul, oto mój kod:
  1. $oForm = new Form_Community();
  2. $oForm->buildForm();
  3. if($oForm->isValid($_POST)){
  4. $aFormValues = $oForm->getValidValues($_POST);
  5. foreach($oForm->getElements() as $oElement){
  6. $oElement->setValue(null);
  7. }
  8. print_array($aFormValues);
  9. }
  10. $aReturnData['form'] = $oForm->renderToArray($oForm);
  11.  


  1. [php]
  2. class Form_Community extends CMS_Abstract_Form{
  3. public function buildForm(){
  4. $this->setAction('');
  5. $this->setMethod('post');
  6.  
  7. $oComunityName = new Zend_Form_Element_Text('community_name');
  8. $oComunityName->setLabel('Nazwa gminy: ');
  9. $oComunityName->setRequired(true)->addErrorMessage('Pole jest wymagane');
  10. $oComunityName->setAttrib('maxlenght',10);
  11. $this->addElement($oComunityName);
  12.  
  13. $oComunityAdmin = new Zend_Form_Element_Text('community_administrator');
  14. $oComunityAdmin->setLabel('Nazwa zarzadcy drog: ');
  15. $oComunityAdmin->setRequired(true)->addErrorMessage('Pole jest wymagane');
  16. $oComunityAdmin->setAttrib('maxlenght',10);
  17. $oComunityAdmin->setAttrib('classs','input-text');
  18. $this->addElement($oComunityAdmin);
  19. $this->addElement('submit','send',array('label'=>'Wyslij'));
  20. }
  21. }

[/php]

Ten post edytował padalec83 31.05.2011, 15:07:41


--------------------
www.silversite.pl
Go to the top of the page
+Quote Post
KrzysiekWildfire
post
Post #4





Grupa: Zarejestrowani
Postów: 93
Pomógł: 11
Dołączył: 27.10.2010
Skąd: Kutno/Poznań

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


ja robię tak:
  1. if ($this->_request->isPost()){
  2. if ($form->isValid($this->_request->getPost())){
  3. ...
  4. }
  5. }

I powinno śmigać
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 - 02:50