Guest User

Untitled

a guest
Jul 29th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. How to generate subform of form - Zend Framework
  2. <?php
  3. $username = new Zend_Form_Element_Text('user');
  4. ...//param for field
  5. $password = new Zend_Form_Element_Password('pwd');
  6. ...//param for field
  7. $name = new Zend_Form_Element_Text('name');
  8. ...//param for field
  9. $submit = new Zend_Form_Element_Submit('submit');
  10. ...//param for field
  11. $this->addElement(array($user,$password,$name,$submit));
  12. $this->addDisplayGroup(array($user,$password,$submit),'login');
  13. $this->addDisplayGroup(array($user,$password,$name, $submit),'create');
  14. ?>
  15.  
  16. class LoginForm extends Zend_Form
  17. {
  18. public function init ()
  19. {
  20. $this->addElement('text', 'user');
  21. $this->addElement('password', 'pwd');
  22. $this->addElement('submit', 'submit');
  23. }
  24. }
  25.  
  26. class RegisterForm extends Zend_Form
  27. {
  28. public function init ()
  29. {
  30. $this->addElement('text', 'user');
  31. $this->addElement('password', 'pwd');
  32. $this->addElement('text', 'name');
  33. $this->addElement('submit', 'submit');
  34. }
  35. }
  36.  
  37. class BaseForm extends Zend_Form_Subform
  38. {
  39. public function init ()
  40. {
  41. $this->addElement('text', 'user');
  42. $this->addElement('password', 'pwd');
  43. }
  44. }
  45.  
  46. class LoginForm extends Zend_Form
  47. {
  48. public function init ()
  49. {
  50. $subform = new BaseForm;
  51. $this->addSubform($subform, 'base');
  52.  
  53. $this->addElement('submit', 'submit');
  54. }
  55. }
  56.  
  57. class RegisterForm extends Zend_Form
  58. {
  59. public function init ()
  60. {
  61. $subform = new BaseForm;
  62. $this->addSubform($subform, 'base');
  63. $this->addElement('text', 'name');
  64.  
  65. $this->addElement('submit', 'submit');
  66. }
  67. }
  68.  
  69. public function loginAction ()
  70. {
  71. $form = new LoginForm();
  72. // More code here
  73.  
  74. $this->view->form = $form;
  75. }
  76.  
  77. public function registerAction ()
  78. {
  79. $form = new RegisterForm();
  80. // More code here
  81.  
  82. $this->view->form = $form;
  83. }
  84.  
  85. $mySubForm->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'))
  86. ->addDecorator('Form');
  87.  
  88. <?php echo $this->mySubForm; ?>
Add Comment
Please, Sign In to add comment