I may have missed the nuances of the tutorials/documentation, so I am posting here as a last result. (Using version 1.1.12.)
I have a number of small form builder configuration files intended to render frequently reused forms. I would like to combine these into a larger form. So let’s say we have a registration form that includes a user form and other nested forms configured from other files… how is that done?
I’ve tried this configuration in the registration file:
return array( 'elements' => array( 'userForm' => array( 'type' => 'form', ), 'passwordForm' => array( 'type' => 'form', ), 'profileForm' => array( 'type' => 'form', ), ), 'buttons' => array( 'submit' => array( 'type' => 'submit', 'label' => 'Submit', ), 'cancel' => array( 'type' => 'button', 'label' => 'Cancel', ), ), );
and here’s a look at the userForm configuration file:
return array( 'elements' => array( 'email' => array( 'type' => 'text', 'maxlength' => 48, ), 'cellPhoneNo' => array( 'type' => 'text', 'maxlength' => 14, ), ), );
Here’s the code from the controller tying it all together:
[...] $form = new CForm('application.views.registration.registerForm'); $userForm = new CForm('application.views.user._form'); $profileForm = new CForm('application.views.userProfile._form'); $passwordForm = new CForm('application.views.password._registerForm'); $userForm->model = new User; $profileForm->model = new UserProfile; $passwordForm->model = new PasswordForm; $form['userForm'] = $userForm; $form['profileForm'] = $profileForm; $form['passwordForm'] = $passwordForm; [...] $this->render('register', array('form'=>$form)); }
This looks like it should work but an exception is thrown in the ‘render’ statement. I’m obviously doing something wrong… suggestions?