Posted By

yanek1988 on 03/03/11


Tagged

zend


Versions (?)

Zend_Form


 / Published in: PHP
 

  1. <?php
  2.  
  3. class Form_Mojform extends Zend_Form {
  4.  
  5. public function init() {
  6. $this->setAttrib('enctype', 'multipart/form-data');
  7.  
  8. // radio (select, checkbox)
  9. $this->addElement('radio', 'opcja', array(
  10. 'label' => 'Wybierz opcję:',
  11. 'multiOptions' => array(1=>'opcja 1', 2=>'opcja 2'),
  12. 'required' => true,
  13. 'registerInArrayValidator' => false,
  14. 'separator' => ''
  15. ));
  16. // text
  17. $this->addElement('text', 'pole_tekstowe', array(
  18. 'label' => 'Wpisz tytuł:',
  19. 'validators' => array(
  20. array('Alnum'),
  21. array('Alpha'),
  22. array('Digits'),
  23. array('EmailAddress'),
  24. array('StringLength', false, array(3,250)),
  25. array('Between', false, array('min' => 0, 'max' => 10)),
  26. array('Date', false, array('format' => 'yyyy-MM-dd HH:mm:ss'))
  27. ),
  28. 'required' => true
  29. ));
  30. // file
  31. $this->addElement('file', 'plik', array(
  32. 'label'=>'Mój plik:',
  33. 'destination' => Bootstrap::$root.'/public/images/',
  34. 'validators' => array(
  35. array('Size', false, 2097152),
  36. array('Extension', false, 'jpg,jpeg,png,gif')
  37. ),
  38. 'maxFileSize' => 2097152,
  39. 'required' => true
  40. ));
  41. // grupa
  42. $this->addDisplayGroup(
  43. array('pole1','pole2','pole3'),
  44. 'gropa_pol',
  45. 'disableLoadDefaultDecorators' => true,
  46. 'decorators' => array(),
  47. 'legend' => 'Grupa pól'
  48. )
  49. );
  50. // usunięcie dekoratorów
  51. $elements = $this->getElements();
  52. foreach ($elements as $elem){
  53. if ($elem instanceof Zend_Form_Element_Hidden)
  54. $elem->removeDecorator('label')->removeDecorator('HtmlTag');
  55. }
  56. // view script dla formularza
  57. $viewScript = new Zend_Form_Decorator_ViewScript();
  58. $viewScript->setViewScript('form.phtml');
  59. $this->clearDecorators();
  60. $this->addDecorator($viewScript);
  61. }
  62.  
  63. }
  64.  
  65. ?>

Report this snippet  

You need to login to post a comment.