Redirect to new page w/ POST data (PHP/Zend)

前端 未结 6 444
青春惊慌失措
青春惊慌失措 2020-12-06 10:02

I\'m trying to figure out how to redirect to a new page (different application, controller, action) and maintain the current POST data.

My app is validating the POST

相关标签:
6条回答
  • 2020-12-06 10:28

    I'm not too familiar with Zend specifically, but there are two approaches I'd take to your problem:

    1. Store the POST data in the session for the life of that request/redirect
    2. Set the redirect to be a POST, and encode the data. Instead of using redirect, just send a new header with POST instead of GET.
    0 讨论(0)
  • 2020-12-06 10:30

    You can use the redirector action helper:

    http://framework.zend.com/manual/1.12/en/zend.controller.actionhelpers.html#zend.controller.actionhelpers.redirector

    This is working for me. It is passing the login credentials from one login screen to another. The 307 may cause the browser to alert the user that the redirect is occurring, a 303 will redirect and populate the credentials on the next page, but not submit the second form.

    $baseUrl = 'https://example.com';
    $this->_redirector = $this->_helper->getHelper('Redirector');
    $this->_redirector->setCode(307)
       ->setUseAbsoluteUri(true)
       ->gotoUrl($baseUrl . '/home/login',
            array('username' => $authForm->getValue('username'),
                  'password' => $authForm->getValue('password')
            )
       );
    
    0 讨论(0)
  • 2020-12-06 10:40

    IMO you can't do a Redirect with POST. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3

    As already said you could save your POST-Data in the Session.

    0 讨论(0)
  • 2020-12-06 10:41

    You can use a Controller _request object

    $this->_request->setPost(array(
        'someKey' => 'someValue'
    ));
    

    And then simply use _forward protected method

    $this->_forward('yourAction', 'yourController', 'yourModule');
    

    Then, in forwarded controller action just call

    $aPost = $this->_request->getPost();
    
    0 讨论(0)
  • 2020-12-06 10:45

    Rather than redirecting the browser to the new location, why not just forward the request from the controller to the other controller?

    return $this->_forward("action", "controller", "module");
    
    0 讨论(0)
  • 2020-12-06 10:49

    Because the client handles the redirection after the server's response I don't think you can do much about this. Firefox for example asks the user whether he/she wants to resend the POST data to the new location or not.

    A nasty solution would be to fill and return a HTML form and auto-submit it with JavaScript. :/

    0 讨论(0)
提交回复
热议问题