Jump to content

Force reload after form-launched download


geminidomino

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

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.