...

View Full Version : Envoke Pop-up on submit & post data



soma56
12-22-2010, 05:38 AM
This one is tricky. I can do this in php, however, I would like to keep everything on the same page. In a nutshell I'd like my users to export some data but after they click the export button I need them to input a key which will then be placed into a variable and the posted.

Here's a simplified version of how script works without the key:



<?PHP
if(isset($_POST['Export'])){
$file = $_POST['Export'];
$hostname = $_SERVER['SERVER_NAME']; $hostname = str_replace('www.', '', $hostname);
$file_location = "http://".$hostname."/filelocation/".$file;
$list = file_get_contents("$file_location");
# filename for download
$filename = "$file.txt"; header("Content-Disposition: attachment; filename=\"$file\""); header("Content-Type: text/plain");
echo $list;
} ?>

<form action="" method="post">
<input type=hidden value="$file" name="Export">
<input type=submit value="Export"></form>


I know this is a javascript category and I have php. However, what I want is javascript. My users cannot access the page (traditionally) because a key needs to first be submitted. This is what I need help with

> Find a way to use javascript when the 'Export' button is pressed to open a pop-up window for the user to submit their key.

> Place there key into a variable.

From there I can use PHP to post the variable, extract the data and allow the user to export.

Something like this:



if(isset($_POST['Export'])){
//The user pressed the export button - use javascript to envoke pop-up

//<!--javascript pop-up code-->
//The user submitted their key - place it in a variable

//<!--javascript code to post key into variable-->

$key = $_GET['key'];
$file = $_POST['Export'];
$hostname = $_SERVER['SERVER_NAME']; $hostname = str_replace('www.', '', $hostname);
$file_location = "http://".$hostname."/filelocation/".$file."php?key=".$key;
$list = file_get_contents("$file_location");
# filename for download
$filename = "$file.txt"; header("Content-Disposition: attachment; filename=\"$file\""); header("Content-Type: text/plain");
echo $list;
} ?>

<form action="" method="post">
<input type=hidden value="$file" name="Export">
<input type=submit value="Export"></form>


If I can get the user to place a key in a simple input box (through a javascript pop-up after they've clicked the button) then I can post the variable and retrieve the data.

Any ideas?

Rowsdower!
12-22-2010, 02:34 PM
Are you absolutely determined to have a separate browser window pop up for this?

It seems to me that you could easily use a lightbox type of effect to present the input element to the user in the exact same page without any worry of popup blockers getting in the way.

If you are set on using an actual popup then take a look here to get some insight about interaction of parent windows with their child popup windows in javascript:

http://www.blazonry.com/javascript/windows.php

You can use some methods there to get the two windows to communicate with each other, and setting a variable would be pretty easy to do this way.

soma56
12-22-2010, 04:25 PM
Are you absolutely determined to have a separate browser window pop up for this?

It seems to me that you could easily use a lightbox type of effect to present the input element to the user in the exact same page without any worry of popup blockers getting in the way.


Sure. I just need a way to pause between so that the user can input a key. Can you elaborate on 'lightbox type of effect' with respect to how this could be done?

soma56
12-23-2010, 06:12 AM
I found a popular lightbox effect that will work great, however, it only works as a link. Here is the original website:

http://www.xul.fr/javascript/lightbox-form-demo.html

Here's a simplified version of what works (link only):



<!--CSS STYLES: http://www.xul.fr/javascript/lightbox-form.css -->
<!--Javascript Source: http://www.xul.fr/javascript/lightbox-form.js -->

//Check if the link was clicked
if(isset($_POST['Export'])){ ?>
//If the link was click envoke the pop-up
$file = $_POST['file'];
<div id="filter"></div>
<div id="box">
<span id="boxtitle"></span>
<form method="GET" action="export.php" target="_parent">
Enter Your Key
<input type="text" name="key">
<input type=hidden value="$file" name="Export">
<input type="submit" value="Export"></form>
</form>
</div>
//Additional code here for processing
<?PHP } ?>
//If link was NOT clicked display initial link


To make the form appearing, <a href="#" onClick="openbox('Title of the Form', 1)">click
here</a>


However, I need to process some variables 'with' the form lightbox. So instead of the user clicking a link how can I make this work by having them click a button within a form?

Something like this:



<form action="" method="post" onClick="openbox('Title of the Form', 1)">
<input type=hidden value="$file" name="file">
<input type=submit value="Export"></form>

soma56
12-23-2010, 07:30 AM
I think I've figured out another way to do this but I need some help calling the function (lightbox above). Currently it's 'onclick'.

Is there any way to make this automatic if the initial form is submitted?


<a href="#" onClick="openbox('Title of the Form', 1)">click
here</a>

The logic is in the comments:



<?PHP
if(isset($_POST['Export'])){

<!--Submit Button Pressed-->
<!--Call the following function!-->
<!--Change:-->
<a href="#" onClick="openbox('Title of the Form', 1)">click
here</a>
<!--...to start automatically-->
} else { ?>

<form action="" method="post">
<input type=hidden value="$file" name="file">
<input type=submit value="Export"></form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum