redirect zend form to another action after validation

For programming and general questions on Zend Framework

redirect zend form to another action after validation

Postby nulele on Wed Jul 22, 2009 9:17 am

Hi everybody,
I'm trying to integrate my ZF app with Pommo (a great newsletters manager).
Pommo has its own registration page where users can subscribe, unsubscribe and update infos.
Looking at the code of the pommo registration page I got the url action of the form (/privatearea/pommo/user/process.php) as well as the form elements name (email and group).

I replicated the pommo registration form with zend form.
I'd like to make my form act this way during validation:
- if the form is NOT valid, return to form and show validation errors
- if the form is valid change the form action to /privatearea/pommo/user/process.php and send the request to that page

This is the code inside my controller to validate the form:
Code: Select all
   
public function newsletterAction()
    {
        $newsletterForm = new Default_Model_NewsletterForm();
        $this->view->newsletterForm = $newsletterForm;
      
       if ($this->getRequest()->isPost())
      {              
          $formData = $this->getRequest()->getPost();   
            
           if ($newsletterForm->isValid($formData))
           {
            //##### here goes the missing code... #####         
            $newsletterForm->setAction('/privatearea/pommo/user/process.php');
            //##### ... or here #####               
         }
         else
         {
            $newsletterForm->populate($formData);
         }
      }
                   
    }

If anyone has some idea, please let me know.
Thank you
nulele
 
Posts: 5
Joined: Mon Jul 20, 2009 8:45 am

Re: redirect zend form to another action after validation

Postby dhaval4linux on Wed Jul 29, 2009 4:11 pm

Use redirect method of Zend_Controller_Helper

Code: Select all
$this->_helper->redirector('actionName', 'controllerName');

If you dont specify controllerName then it will take same controller.
Also there is another method $this->_redirect();

Check out ZF manual..
Best Regards,
Dhaval
dhaval4linux
 
Posts: 161
Joined: Fri May 22, 2009 2:35 pm

Re: redirect zend form to another action after validation

Postby ocorso on Wed Apr 04, 2012 8:25 pm

i am using the redirect action helper but it seems the valid form data is not being sent to the redirect action and also the method of the request has changed from POST to GET. how do we preserve the entire request yet show the user a new URL?
ocorso
 
Posts: 1
Joined: Wed Apr 04, 2012 8:23 pm

Re: redirect zend form to another action after validation

Postby didgewind on Sat Sep 29, 2012 5:33 am

maybe using the _forward() method?
didgewind
 
Posts: 1
Joined: Sat Sep 29, 2012 5:32 am


Return to Zend Framework

Who is online

Users browsing this forum: No registered users and 2 guests