-- Justin Hendrickson <[EMAIL PROTECTED]> wrote
(on Tuesday, 12 February 2008, 01:56 PM -0600):
> I'm trying to put together a simple Zend_Form setup for a multipaged form, but
> the documentation on implementing the multipage part is a bit sparse. 

I'm aware of that; I haven't had a chance to work up more advanced use
cases and examples for this bit of functionality yet.

A note or two below:

> Once the form object is setup with the subforms, what's the "right
> way" to render and validate the subforms and process the results?
> 
> This is what I have right now:
> 
> <?php
> require_once 'ApplicationController.php';
> 
> require_once 'Zend/Form.php';
> 
> class IndexController extends ApplicationController
> {
> 
>     public function siteInformationAction()
>     {
>         $subform = $this->_getForm()->getSubForm('site_information');
> 
>         if ($this->getRequest()->isPost() && $subform->isValid($this->
> getRequest()->getPost())) {
>             return $this->getHelper('redirector')->gotoRoute(

You'll probably want to store the data from validating the subform in
your session so you can retrieve it later; otherwise, your data will be
lost. There's a variety of ways to do that -- using $_SESSION directly,
or using Zend_Session -- so I won't go into details.


>                 array(
>                     'action' => 'personalInformation'
>                 )
>             );
>         }
> 
>         $this->view->form = $subform;
>         $this->render('form');
>     }
> 
>     public function personalInformationAction()
>     {
>         $subform = $this->_getForm()->getSubForm('personal_information');
> 
>         if ($this->getRequest()->isPost() && $subform->isValid($this->
> getRequest()->getPost())) {
>             var_dump($this->_getForm()->getValues());
>             exit;
>         }
> 
>         $this->view->form = $subform;
>         $this->render('form');
>     }
> 
>     private function _getForm()
>     {
>         return new Zend_Form(array(
>             'method' => 'POST',
>             'subforms' => array(
>                 'site_information' => new Zend_Form(array(
>                     'elements' => array(
>                         'username' => array(
>                             'text',
>                             array(
>                                 'label' => 'Username',
>                                 'required' => true,
>                                 'validators' => array(
>                                     'NotEmpty'
>                                 )
>                             )
>                         ),
>                         'password' => array(
>                             'password',
>                             array(
>                                 'label' => 'Password',
>                                 'required' => true,
>                                 'validators' => array(
>                                     'NotEmpty'
>                                 )
>                             )
>                         ),
>                         'submit_site_information' => array(
>                             'submit',
>                             array(
>                                 'value' => 'Next Page'
>                             )
>                         )
>                     )
>                 )),
>                 'personal_information' => new Zend_Form(array(
>                     'elements' => array(
>                         'name' => array(
>                             'text',
>                             array(
>                                 'label' => 'Name',
>                                 'required' => true,
>                                 'validators' => array(
>                                     'NotEmpty'
>                                 )
>                             )
>                         ),
>                         'street' => array(
>                             'text',
>                             array(
>                                 'label' => 'Street',
>                             )
>                         ),
>                         'city' => array(
>                             'text',
>                             array(
>                                 'label' => 'City'
>                             )
>                         ),
>                         'state' => array(
>                             'text',
>                             array(
>                                 'label' => 'State'
>                             )
>                         ),
>                         'zip' => array(
>                             'text',
>                             array(
>                                 'label' => 'Zip'
>                             )
>                         ),
>                         'submit_personal_information' => array(
>                             'submit',
>                             array(
>                                 'value' => 'Submit'
>                             )
>                         )
>                     )
>                 ))
>             )
>         ));
>     }
> 
> }
> 
> Unfortunately, I'm obviously missing something because 
> var_dump($this->_getForm
> ()->getValues()); is giving me array()
> . Is my approach completely off? Also, how do you go about preventing someone
> from manually going to the personalInformationAction()?

-- 
Matthew Weier O'Phinney
PHP Developer            | [EMAIL PROTECTED]
Zend - The PHP Company   | http://www.zend.com/

Reply via email to