Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to generate subform of form - Zend Framework
- <?php
- $username = new Zend_Form_Element_Text('user');
- ...//param for field
- $password = new Zend_Form_Element_Password('pwd');
- ...//param for field
- $name = new Zend_Form_Element_Text('name');
- ...//param for field
- $submit = new Zend_Form_Element_Submit('submit');
- ...//param for field
- $this->addElement(array($user,$password,$name,$submit));
- $this->addDisplayGroup(array($user,$password,$submit),'login');
- $this->addDisplayGroup(array($user,$password,$name, $submit),'create');
- ?>
- class LoginForm extends Zend_Form
- {
- public function init ()
- {
- $this->addElement('text', 'user');
- $this->addElement('password', 'pwd');
- $this->addElement('submit', 'submit');
- }
- }
- class RegisterForm extends Zend_Form
- {
- public function init ()
- {
- $this->addElement('text', 'user');
- $this->addElement('password', 'pwd');
- $this->addElement('text', 'name');
- $this->addElement('submit', 'submit');
- }
- }
- class BaseForm extends Zend_Form_Subform
- {
- public function init ()
- {
- $this->addElement('text', 'user');
- $this->addElement('password', 'pwd');
- }
- }
- class LoginForm extends Zend_Form
- {
- public function init ()
- {
- $subform = new BaseForm;
- $this->addSubform($subform, 'base');
- $this->addElement('submit', 'submit');
- }
- }
- class RegisterForm extends Zend_Form
- {
- public function init ()
- {
- $subform = new BaseForm;
- $this->addSubform($subform, 'base');
- $this->addElement('text', 'name');
- $this->addElement('submit', 'submit');
- }
- }
- public function loginAction ()
- {
- $form = new LoginForm();
- // More code here
- $this->view->form = $form;
- }
- public function registerAction ()
- {
- $form = new RegisterForm();
- // More code here
- $this->view->form = $form;
- }
- $mySubForm->addDecorator('HtmlTag', array('tag' => 'dl', 'class' => 'zend_form'))
- ->addDecorator('Form');
- <?php echo $this->mySubForm; ?>
Add Comment
Please, Sign In to add comment