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

Asked
Active3 hr before
Viewed126 times

7 Answers

redirect
90%

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.,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.,In my exampleAction (Zend_Controller_Action), I check to see if var1 == foo, and if it does I want to redirect (302) to /app2/example with that same POST data. Something maybe like this?, 1 Well, it seems like would have been exactly what I wanted, except that for some reason we don't have our modules configured correctly. We've got some wacky set up where each module accessed is set up as the default module, and it's unaware of the other modules. Go figure. Thanks though for the verification, gnarf! – angrychimp Aug 21 '09 at 18:02

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");
load more v
88%

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 data and if a certain criteria is met, I want to redirect to a different location, but make sure the POST data is passed as POST data to that new page. Here's a rough example:,In my exampleAction (Zend_Controller_Action), I check to see if var1 == foo, and if it does I want to redirect (302) to /app2/example with that same POST data. Something maybe like this?,Rather than redirecting the browser to the new location, why not just forward the request from the controller to the other controller?

My app is validating the POST data and if a certain criteria is met, I want to redirect to a different location, but make sure the POST data is passed as POST data to that new page. Here's a rough example:

POST / app1 / example HTTP / 1.1
Host: example.com
Content - Type: application / x - www - form - urlencoded
Content - Length: 17
var1 = foo & var2 = bar

In my exampleAction (Zend_Controller_Action), I check to see if var1 == foo, and if it does I want to redirect (302) to /app2/example with that same POST data. Something maybe like this?

HTTP / 1. x 302 Found
Location: /app2/example
Content - Type: application / x - www - form - urlencoded
Content - Length: 17
var1 = foo & var2 = bar

I can see how to create a new HTTP request using Zend_Http_Client, but I'm not looking to simply request the page and display the content. Should I still be looking to use Zend_Http_Client anyway? At the moment I'm playing with stuff like this:

$this - > getResponse() - > setRedirect('/app2/example/', 302);
$this - > getResponse() - > setBody(http_build_query($this - > _request - > getPost()));
load more v
72%

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 data and if a certain criteria is met, I want to redirect to a different location, but make sure the POST data is passed as POST data to that new page. Here's a rough example:,In my exampleAction (Zend_Controller_Action), I check to see if var1 == foo, and if it does I want to redirect (302) to /app2/example with that same POST data. Something maybe like this?,Rather than redirecting the browser to the new location, why not just forward the request from the controller to the other controller?

My app is validating the POST data and if a certain criteria is met, I want to redirect to a different location, but make sure the POST data is passed as POST data to that new page. Here's a rough example:

POST / app1 / example HTTP / 1.1
Host: example.com
Content - Type: application / x - www - form - urlencoded
Content - Length: 17
var1 = foo & var2 = bar
load more v
65%

This plugin can be invoked with two arguments:,This plugin can be invoked with three arguments:,When a user sends a POST request (e.g. after submitting a form), their browser will try to protect them from sending the POST again, breaking the back button, causing browser warnings and pop-ups, and sometimes reposting the form. Instead, when receiving a POST, we should store the data in a session container and redirect the user to a GET request.,Returns the Zend\Session\Container instance in which the flash messages are stored.

1
load more v
75%

Next, your controller extracts the submitted data and asks the form model to validate it. If there were input errors, you display the form again, asking the user to correct input errors. If the data is correct, you process the data with your business logic layer and (usually) redirect the user to another web page. ,First, you display the form and its fields on a web page, prompting user for input. Once the user fills the form fields, he clicks the Submit button and sends the data to server. ,In line 19 we retrieve the raw data submitted by the user. We extract all the POST variables with the help of the Params controller plugin. The data is returned in the form of an array and saved into the $data variable. ,As you might already know, the way the site user works with form is typically an iterative process (schematically illustrated by figure 7.18):

The code example below illustrates how to implement this typical workflow in your controller's action method:

< ? php
namespace Application\ Controller;

use Application\ Form\ ContactForm;
// ...

class IndexController extends AbstractActionController {
   // This action displays the feedback form
   public
   function contactUsAction() {
      // Create Contact Us form
      $form = new ContactForm();

      // Check if user has submitted the form
      if ($this - > getRequest() - > isPost()) {
         // Fill in the form with POST data
         $data = $this - > params() - > fromPost();
         $form - > setData($data);

         // Validate form
         if ($form - > isValid()) {

            // Get filtered and validated data
            $data = $form - > getData();

            // ... Do something with the validated data ...

            // Redirect to "Thank You" page
            return $this - > redirect() - > toRoute('application', ['action' => 'thankYou']);
         }
      }

      // Pass form variable to view
      return new ViewModel([
         'form' => $form
      ]);
   }
}
load more v
40%

if (!isset($adminLogin - > loggedin)) {
   $baseUrl = new Zend_View_Helper_BaseUrl();
   $this - > getResponse() - > setRedirect($baseUrl - > baseUrl().
      '/something');
}
22%

@egeloen it might help if you could say specifically which request headers you are expecting to be preserved.,@tfountain There is no specific headers, I just expects zf2 to forward any original request headers.,Yes but if the strictredirects is set to false, shouldn't the headers be forwarded anyway?,You need certain headers to be in the last Request. That is it?

$response = $this - > getResponse();
$response - > getHeaders() - > addHeaderLine('Location', $url);
$response - > setStatusCode(302);
return $response;
load more v

Other "redirect-undefined" queries related to "Redirect to new page w/ POST data (PHP/Zend)"