geminidomino Posted October 5, 2009 Share Posted October 5, 2009 I'm curious if, and more importantly how, this is possible: I have a form that, when submitted, reads and frobs some database information and proceeds to create a download file "dynamically" (never saved to disk, proceeds directly to browser download prompt). That part functions fine, but what I'd like to do now, if possible, is force the original page with the form on it to reload at this point. There's a lot of material on each of these operations, all over the web, but hooking the two together seems to be rarely-explored territory (at least according to my googling), other than a forum post from 2003 saying it was essentially impossible. I've tried adding a header refresh and a javascript refresh after the file is generated, but it seems that, it puts all output at the end of the downloaded file. I also tried putting in a refresh header (delayed) but that never seemed to trigger either. Quote Link to comment Share on other sites More sharing options...
gr1zzly Posted October 5, 2009 Share Posted October 5, 2009 If the function that prepared and issued the download is stored in a different file to the page with the form (i.e. the form posts to a script instead of it's host page). So long as the script doesn't output anything to the page you could use a simple header location re-direct: - header("Location: $url"); I'm not sure if the download initiating would constitute as 'output' though, which would result in an error "headers already sent" or something like that. In which case though, having the prepared download stored as a variable that can be passed back to the calling page with the re-direct where it is then issued to the browser download prompt may negate this. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 5, 2009 Share Posted October 5, 2009 This is VERY strange. I was just having the same issue. I was just coming here to open a post and I see yours at the very top. I second the original poster's question. In his situation (same as mine) header redirect won't work. That just depends on the type of download. Meanwhile I am also experimenting right now on using Javascript to handle the form submissions entirely and see if that'll allow for multiple submissions. If I get something work I will post here to help you as well, and if anyone else has any other suggestions they offer here it'll help us both. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 5, 2009 Share Posted October 5, 2009 This has me stumped. After reviewing your issue and my own...I am running out of ideas. Header doesn't work because it's already being passed. window.location doesn't work, opening it a new window doesn't work. The first 50 pages worth of google for 3-4 different terms doesn't work. Still looking, if anyone has solutions to either of these issues feel free to jump in. Quote Link to comment Share on other sites More sharing options...
geminidomino Posted October 5, 2009 Author Share Posted October 5, 2009 I'm not sure if the download initiating would constitute as 'output' though, which would result in an error "headers already sent" or something like that. Alas, it does. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 5, 2009 Share Posted October 5, 2009 I have something I am trying now that might work, give me a minute. Quote Link to comment Share on other sites More sharing options...
gr1zzly Posted October 5, 2009 Share Posted October 5, 2009 Even though the prepared download is "never saved to disk" surely the sever must store it in a temporary folder/file? If so would it be possible to process the preparation of the download in a script file but save the action of submitting the download to the original pages code, allowing a header re-direct from the script? - i.e. save the temp location, pass it back to the page with the refresh then submit the download. The only other alternative I could see would be a Javascript page refresh, but this has accessibility issues and is often just as tricky to implement. Beside businessman already said "window.location doesn't work". Will think on it... Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi Not sure why exactly you are doing this. However would it be possible to have a hidden form, and use Javascript to copy the fields in the displayed form to the hidden form, wipe the fields in the displayed form and then submit the hidden form to generate the download file. All the best Keith Quote Link to comment Share on other sites More sharing options...
geminidomino Posted October 5, 2009 Author Share Posted October 5, 2009 Hi Not sure why exactly you are doing this. However would it be possible to have a hidden form, and use Javascript to copy the fields in the displayed form to the hidden form, wipe the fields in the displayed form and then submit the hidden form to generate the download file. All the best Keith Basically, because this operation will be done very often, and the output is basically just formatted data. It also updates some database values though, so the page would need a reload, rather than just wiping the form, in order to regenerate the list with the right entries. Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted October 5, 2009 Share Posted October 5, 2009 I gave up for the time being. Nothing I tried worked. Everything I found on Google states it's not possible. I have tried: 1) JavaScript refresh 2) PHP Redirect 3) Iframe with form..then refresh Iframe. I have tried another variety of little tricks, work-around, and hacks and nothing is working. This seems to be a lost cause. The only thing I haven't tried is actually building the file and save it to a location then prompt for download..but I don't feel like going to all that trouble..and in-theory it sounds like it would cause the same issue. Naturally..this would be nice for the "user-friendly" department..but it's not coming together. It's standard functionality..but I don't know if there "is" a workaround that can be implemented for it to function the way we're wanting. Then the only other solution would be providing a download link..but that just defeats the purpose. I was going to download http://www.formtofile.com/ and see how that does it and see if it has a workaround..but I don't really feel like going to the trouble after everything else I tried. Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi How about using javascipt to link to the download in a new window while submitting the form itself to be refreshed in the current window. All the best Keith Quote Link to comment Share on other sites More sharing options...
geminidomino Posted October 5, 2009 Author Share Posted October 5, 2009 Hi How about using javascipt to link to the download in a new window while submitting the form itself to be refreshed in the current window. All the best Keith Not sure. That might be a possibility if $_GET can handle arrays like $_POST, but I'll have to consider it further. Not sure I want to be throwing those URLs out. Quote Link to comment Share on other sites More sharing options...
kickstart Posted October 5, 2009 Share Posted October 5, 2009 Hi That is an issue and I can understand why you want to be careful. What you could do to remove that hassle is use Ajax to load up the form details (POST wise) and save them on the server, returning a unique id. Then once Ajax has returned the unique key you then just fire off the script to generate the document in a new window passing the unique key as the only item on the query string. Would be easy enough to delete the data from the server once the document is generated. All the best Keith Quote Link to comment Share on other sites More sharing options...
geminidomino Posted October 5, 2009 Author Share Posted October 5, 2009 *Facepalm* Your second to last response actually gave me the easiest answer. Turns out, the <FORM> element can accept a "target" tag... so then I can refresh on on_submit... I should 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.