Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2008
    Posts
    36
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Envoke Pop-up on submit & post data

    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:

    Code:
    <?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:

    Code:
    	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?
    Last edited by soma56; 12-22-2010 at 05:48 AM. Reason: Grammar

  • #2
    Senior Coder Rowsdower!'s Avatar
    Join Date
    Oct 2008
    Location
    Some say it's everything.
    Posts
    2,027
    Thanks
    5
    Thanked 397 Times in 390 Posts
    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.
    The object of opening the mind, as of opening the mouth, is to shut it again on something solid. G.K. Chesterton
    See Mediocrity in its Infancy
    It's usually a good idea to start out with this at the VERY TOP of your CSS: * {border:0;margin:0;padding:0;}
    Seek and you shall find... basically:
    validate your markup | view your page cross-browser/cross-platform | free web tutorials | free hosting

  • #3
    New Coder
    Join Date
    Jul 2008
    Posts
    36
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Rowsdower! View Post
    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?

  • #4
    New Coder
    Join Date
    Jul 2008
    Posts
    36
    Thanks
    7
    Thanked 0 Times in 0 Posts
    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):

    Code:
    <!--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:

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

  • #5
    New Coder
    Join Date
    Jul 2008
    Posts
    36
    Thanks
    7
    Thanked 0 Times in 0 Posts
    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?

    Code:
    <a href="#" onClick="openbox('Title of the Form', 1)">click 
      here</a>
    The logic is in the comments:

    Code:
    <?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>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •