I've developed a php/javascript front end to a mysql data base. One of the things it does is create instantaneous reports in .pdf format. These open up in a separate window, where people can save them, print them, whatever.
I wrote this a few years ago, and since I had no formal training, this is how I did it: I used javascript to open up a new window. It then uses a bunch of document.write() functions to create a form in that window, php fills this up with hidden inputs, then the original page 'submits' the form.
The open window then calls a php report generator, and everything seems to work.
I guess I'm asking if there is a better way to do this? (It stopped working with Safari after a software update, but it works with Safari 3.) I am in the middle of some serious rewriting, and need to know if there are any issues with his method.
--Dave
Popup Reports
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Popup Reports
I fully don't understand it ... but it sounds a little crazy.dhampson wrote:It then uses a bunch of document.write() functions to create a form in that window, php fills this up with hidden inputs, then the original page 'submits' the form.
I would need to know how it "fills this up" and how it "submits the form"...
(#10850)
Re: Popup Reports
This is how I current create a form in the popwindow.
Submitting calls the php function which then streams a .pdf file into the report window.
I was hoping there was a more elegant way of doing this. Especially since it would not work under Safari on the Mac, which was my main browser.
--Dave
Code: Select all
reportWindow.document.write("<input type='hidden' id='Title' name='Title' value='' >");
// several of these
reportWindow.document.getElementById('Title').value = document.getElementById('Title').value;
//several of these
//btw, I tried combing these two lines into one, but it wouldn't work.
reportWindow.document.getElementById('tempForm').submit();I was hoping there was a more elegant way of doing this. Especially since it would not work under Safari on the Mac, which was my main browser.
--Dave
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Popup Reports
I think an Ajax edit in place would a better, more modern implementation than what you have right now.
(#10850)
Re: Popup Reports
And what about using one of the existing PHP PDF libraries, like fpdf? No need for complex javascript/ajax stuff. Post a form and let the library write it to the pdf
Re: Popup Reports
I use fpdf to create my .pdf files. I guess I was looking for a more elegant way to get this started. It's easy to dump .php output to a separate window, it's another thing to pass 10-20 parameters. Generating a form filled with hidden values seems sloppy, and relies on javascript, which was still inconsistent when I first wrote the software.
I thought about simply using a Global Variable, but for reason decided against it. If I create the global variable, then someone else does right away, my report may display the wrong values. (Or could it?) The other thing I thought about was memory leaks. I can create global variables with unique ID's, but I'm not sure about how garbage collection works. (Enlightenment please?)
--Dave
I thought about simply using a Global Variable, but for reason decided against it. If I create the global variable, then someone else does right away, my report may display the wrong values. (Or could it?) The other thing I thought about was memory leaks. I can create global variables with unique ID's, but I'm not sure about how garbage collection works. (Enlightenment please?)
--Dave