Forum Moderators: coopster
What I'd like to do is to have that report in a pop up window rather than update the same page. The problem is, how do I pass the form vars to the report script via a javascript pop up?
I guess one way is to pass the vars via the url string similar to:
<form action=
.
.
<A HREF=javascript:popupwin"http://www.widgets.co.uk/report.php?code=<?php print $code;?>&colour=<?php print $colour;?>")search widgets</A>
That would work fine as it reads the form data $code and $colour and fires up report.php with passed variables.
But the form has dozens and dozens of input, check boxes and radio buttons: It will be a nightmare to create the url string and I'm sure the string would be too long anyway.
How can I get the report.php to read the form vars sort of 'globally' like they do if the form.php just called the report.php directly?
Option 1:
Put the form data into a session which can be accessed by PHP in the pop-up.
Option 2:
Do the form validation on the same level as the form, and have the validation page both store the report data in hidden form fields and generate the pop-up. Then access the hidden form fields from the pop-up using the Javascript DOM, referencing the opening window.
That ought to do it.
The <form> tag is very similar to the <a> tag. It requests/links to a new page. The main difference is in <form>'s ability to set a METHOD and gather its <input> data into the request.
The "action" attribute of the <form> tag works just like the "href" attribute of the <a> tag.
The "target" attribute works similarly in both tags - it opens a new window for the page request.
Hope this helps.
There is another method which would give you more control over the popup. It's complicated, but I've had to use a similar technique before. It's all done with Javascript, so all that I mention below goes within <script> tags. You should put it all into a function if you want it to be triggered by the click of a button or OnSubmit.
This is all done from the parent window. What you're doing is creating a new window, writing an entire HTML form into that window (which is basically a "hidden" version of the same form on the parent page), submitting that form, then switching the focus to that window.
The code below may not work as-is, but it'll give you an idea of what I'm talking about.
1) open a popup window with all your window preferences
popup = window.open('','popup',blah blah blah)
2) write a form into that window, with all your data in "hidden" input tags
popup.document.write("<form name='myform' action='myscript.php' method='post'>");
popup.document.write("<input type='hidden' name='address' value='" + document.parentform.address.value + "'>");
popup.document.write("</form>");
3) Submit that form from the parent page
popup.document.forms.myform.submit();
4) Focus on the new window
popup.focus();
et voila - your data is passed into the new window without using any querystring in the address. Doesn't that seem sneaky?