rossbar Posted October 30, 2014 Share Posted October 30, 2014 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! Quote Link to comment Share on other sites More sharing options...
MDCode Posted October 30, 2014 Share Posted October 30, 2014 Based on how you're describing it, I'm not even sure that's possible. You want the file to download on a page, and on that same page serve a redirect? If so, that's not possible. Quote Link to comment Share on other sites More sharing options...
requinix Posted October 30, 2014 Share Posted October 30, 2014 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 Quote Link to comment Share on other sites More sharing options...
rossbar Posted October 30, 2014 Author Share Posted October 30, 2014 Thank you for your input guys...I really appreciate it Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.