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
https://forums.phpfreaks.com/topic/292154-redirect-after-script-processes/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.