Jump to content

redirect after script processes


rossbar

Recommended Posts

Hi there, 

 

I have a client who has a form on a php page that posts data to a script.  That script process the post data and generates a pdf which comes back and is automatically downloaded in the user's browser.  They would like to redirect the user to a separate page after this process is complete.  I have tried redirecting by adding :

 

header( 'Location: http://www.yoursite.com/new_page.html' ) ;

 
to the bottom of the php script but I don't think this is working b/c the user doesn't actually go to that script page ever.  I have also tried incorporating a redirect with jQuery based on the submit button, but it never seems to execute...it is as if the pdf download script prevents the jQuery redirect from occurring.  
 
I tried utilizing ajax to submit the form data to the script and was then going to redirect after a successful response, but I don't think the form data is being sent in the proper format and that seems like a convoluted solution to a simple problem.  Any ideas?  Or should I stick with the Ajax/jQuery approach?  
 
Thanks!
 
 

 

Link to comment
Share on other sites

You cannot do both a download and a redirect.

 

The general workaround is to redirect first, then "redirect" to the download. Couple ways you could do that but the one I'd go for is:

1. POST to the same place as before, generate the PDF, and store it somewhere temporarily with a unique identifier

2. Redirect to the new_page.html with something in the session or query string indicating the PDF to download

3. Have new_page.html do a client-side redirect (eg, a or Javascript) to the download location

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.