www.webdeveloper.com
Results 1 to 8 of 8

Thread: [RESOLVED] passing variables to popup window from form

  1. #1
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440

    resolved [RESOLVED] passing variables to popup window from form

    I posted a similar message on the PHP thead, but no answer there.

    I have a form that uses javascript to launch a popup window, and the popup is supposed to aquire the data that was POSTed from the form. But it does not.

    The form worked fine as long as the new page was not a popup.

    doesn't work;
    Code:
    <FORM name='contact' ACTION="javascript:openwins('myfile.php')" METHOD='POST'>
    <inputs and submit buttons here>
    </FORM>
    works;
    Code:
    <FORM name='contact' 'ACTION="myfile.php" METHOD='POST'>
    <inputs and submit buttons here>
    </FORM>
    Both snippets launch page 'myfile.php', but the post data is not accessible in the popup version. I am just using $var1 = $_POST['var1']; <php code>
    to bring in the data in both cases.

    The window popup code is pretty straight forward;
    Code:
    function openwins(page) {
    sitewindow = window.open(page,'myfile.php','resizable=1,left=0,top=0,toolbar=no,menubar=no,scrollbars=yes,width=450,height=200')
            }
    Any tips?

  2. #2
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    HTML Code:
    <form onsubmit="openwins('about:blank')" action='myfile.php' target='sitewindow' ....
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  3. #3
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    That did not work. It opened a popup and another window. The popup named about:blank was blank, the other window had my error messages for bad (no) data.

  4. #4
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    you need to make the pop-up name match the target:
    Code:
    window.open(page,'sitewindow',....
    And it should submit the data, no reason why it shouldn't.
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  5. #5
    Join Date
    Mar 2007
    Posts
    946
    Why not use javascript to grab the info from the form fields and place it in the window.open function attaching it to the file like example.php?field1=field1&field2variable=field2variable...

  6. #6
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    Quote Originally Posted by skywalker2208 View Post
    Why not use javascript to grab the info from the form fields and place it in the window.open function attaching it to the file like example.php?field1=field1&field2variable=field2variable...
    Because that's naughty and would break the form for about 10% of users.
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  7. #7
    Join Date
    Mar 2007
    Posts
    946
    what is wrong with naughty?

  8. #8
    Join Date
    Jan 2006
    Location
    MN
    Posts
    440
    Thanks for the input. I decided to go a different way however.

    Went with more PHP and returned the form to PHP_SELF. I then processed the form, and popped a javascript alert using a PHP generated message. That seems to work and is less obtrusive to the user.

    Just have this little bit of javascript;

    Code:
    <script language="JavaScript" type="text/javascript">
    //<!--
    function disp_alert()
    	{
    	msg = "<?php echo $error_message ?>"
    	if (msg !="")
    		{	
    		alert(msg) 
    		}		
    	}
    
    disp_alert()
    // -->
    </script>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles