Redirect to New Page W/ Post Data (Php/Zend)

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

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");

Zend Framework forward request with post http method

Yes this is possible, Try using following:

$this->_request->setPost(array('param_name' => $paramValue));
$this->_forward('actionName', 'controller', 'module');

Zend: Redirect to Action with parameters

Use the Zend_Controller_Action::redirect() method (which just passes through to Sarfraz's helper method)

$this->redirect('/module/controller/action/username/robin/email/robin@example.com');

Note: _redirect() method is deprecated as of Zend Framework 1.7. Use redirect() instead.

And then in the called action:

$username = $this->_getParam('username');
$email = $this->_getParam('email');

_getParam() takes a second optional argument which is set to the variable as a default if the parameter isn't found.

Zend Framework: How to redirect as a POST request?

The Referer is sent as a header, simply:

$client = new Zend_Http_Client($uri);
$client->setHeaders('Referer', 'http://www.yourwebsite.com/');
$client->request(Zend_Http_Client::POST);

How to redirect to Home page (Default page) in zend framework 2?

If you can’t tell what is your home route name, you have at least two options:

  1. Make it configurable — put home route name in your module/application config and retrieve it in the controller.
  2. Just redirect to /:

    return $this->redirect()->toUrl('/');

Zend Framework: How to POST data to some external page (e.g. external payment gate) without using form?

I would like to have a user redirected to an external credit card gate. Of course I have to POST some user info to that gate, but I don't know how exactly can I do this.

Using a form is the only method available. The RFC states that the user should explicitly agree to sending a POST (i.e. click on a submit button).

I know that I could do this by generating a html form with hidden or read-only fields and have a user click "Submit" button. But this solution is not perfect, because all the form data could be easily changed using e.g.

It is no more secure that using a redirect as the header data can be modified without too much of a problem. There are even Firefox plugins to do it.

Passing parameters using a Zend Framework redirect without appending to URL

I'm not super familiar with ZF's controller system so I can't give you a bespoke recommendation.

Is using a session value out of the question? Another popular framework, symfony, uses what they call "flash" variables which are session values that survive for only 1 more request.

I'm sure you could do something similar with ZF.

Redirect to previous page in zend framework

First, you need to grab the original url for the redirection.
You can do that by the Zend_Controller_Request class via:

$url = Zend_Controller_Front::getInstance()->getRequest()->getRequestUri();

or simply by:

$url = $_SERVER['REQUEST_URI'];

Then, the tricky part is to pass it through the user request.
I recommend to use the library Zend_Session, despite using a POST parameter is also legitimate:

$session = new Zend_Session_Namespace('Your-Namespace');
$session->redirect = $_SERVER['REQUEST_URI'];

Please note that the address we kept includes the base path.
To redirect the client in the controller class, disable the option 'prependBase' to lose the base path insertion:

$this->_redirect($url, array('prependBase' => false));

Zend Redirecting

Both the button and the anchor are calling the page! So the first time it runs it's ok then it runs again and redirects me.

Removed the button.



Related Topics



Leave a reply



Submit