?
Solved

How to force a new pop-up window when 'Submit' button is clicked

Posted on 2011-10-19
10
Medium Priority
?
381 Views
Last Modified: 2012-06-27
Hello to everyone,

I have a php/html form script where the user enters some details and a result is returned. Here's part of the form used:

  <form id="form1" name="form1" method="post" action="">
    <p>Encrypted Password:
      <input name="encrypted" maxlength="128" size="50" type="text" id="encrypted" />
&nbsp;&nbsp;&nbsp;<input name="dec" type="submit" id="dec" value="Submit" />

What I want to do is when the user presses the 'Submit' button, I'd like a new window to pop up, that will load a specific URL I will provide.

Any help is much appreciated.

Thank you.
0
Comment
Question by:kosmas
  • 5
  • 3
  • 2
10 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 36997700
Add
target="_blank"
To the form tag
0
 
LVL 19

Expert Comment

by:xterm
ID: 37003340
Try this:

<form method=post target=_self>
<input type=submit value=Submit onClick="return openWindow('$url',500,300);">
</form>
0
 

Author Comment

by:kosmas
ID: 37003925
Xterm,  would you be kind enough to actually inset your suggested code into the one I have already pasted?   The code you suggest, should not modify the functionality of the existing form.

Many thanks
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 19

Expert Comment

by:xterm
ID: 37004377
Absolutely, and glad you posted back, because I forgot to include the javascript that you'll need for that function to work.  Here you go:


<html>

<head>
<script language=JavaScript>
  function openWindow(url,width,height) {
    popupWin = window.open(url, 'remote', 'scrollbars=0, resizable=0,width='+width+',height='+height);
    return false;
  }
</script>
</head>


<form id="form1" name="form1" method="post" action="">
    <p>Encrypted Password:
      <input name="encrypted" maxlength="128" size="50" type="text" id="encrypted" />
&nbsp;&nbsp;&nbsp;<input name="dec" type="submit" id="dec" value="Submit" onClick="return openWindow('http://www.someurl.com',500,300);"/>
</form>

</html>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37004435
"not change functionality"
your code will stop submission and not work in case of popup blockers
kosmas: is the popup unrelated to the form result?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37004723
I suggest you return the following from the form submission

<script type="text/javascript">
window.onload=function() {
  var w = window.open("somepage.html","_blank","width=400,height=400");
  if (!w) alert('Sorry, you have blocked popups')
}
</script>

Alternatively ajax the form result and show the popup in that part of the script
0
 

Author Comment

by:kosmas
ID: 37009435
To make this clear for everyone, here is the full code of the page.  I'd like when someone presses the 'submit' button, the script to continue as it does now, but also pop up an additional window with a URL that I will provide.  

You can use the code below and post it with your recommended changes.

Many thanks everyone!

  <form id="form1" name="form1" method="post" action="">
    <p>Encrypted Password:
      <input name="encrypted" maxlength="128" size="50" type="text" id="encrypted" />
&nbsp;&nbsp;&nbsp;<input name="dec" type="submit" id="dec" value="Submit" />
    <br/>      
    <br/>
    Password:
    <input name="decrypted" type="text" size="50" id="decrypted" value="
<?php
    $Regex = "/^[A-z0-9]+$/";

    if(isset($_POST['encrypted'])) {
        if(!strlen($_POST['encrypted'])) {
            echo "Input was empty";
            return;
        }
        if(preg_match_all($Regex, $_POST['encrypted'], $Matches)) {
            $command = "./decrypt.pl ".$_POST['encrypted'];
            htmlspecialchars(system($command));
        } else {
            echo "Invalid input";
            return;
        }
    }
?>
"/>
<br>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 37010230

<form id="form1" name="form1" method="post" action="">
    <p>Encrypted Password:
      <input name="encrypted" maxlength="128" size="50" type="text" id="encrypted" />
&nbsp;&nbsp;&nbsp;<input name="dec" type="submit" id="dec" value="Submit" />
    <br/>      
    <br/>
    Password:
    <input name="decrypted" type="text" size="50" id="decrypted" value="
<?php
$ok = false;
    $Regex = "/^[A-z0-9]+$/";

    if(isset($_POST['encrypted'])) {
        if(!strlen($_POST['encrypted'])) {
            echo "Input was empty";
            return;
        }
        if(preg_match_all($Regex, $_POST['encrypted'], $Matches)) {
            $command = "./decrypt.pl ".$_POST['encrypted'];
            htmlspecialchars(system($command));
            $ok=true;
        } else {
            echo "Invalid input";
            return;
        }
    }
if ($ok) {?>
<script type="text/javascript">
window.onload=function() {
  var w = window.open("somepage.html","_blank","width=400,height=400");
  if (!w) alert('Sorry, you have blocked popups')
}
</script>
<?php
}
?>
"/>
<br>

Open in new window

0
 

Author Comment

by:kosmas
ID: 37012945
mplungjan,

Unfortunately the script did not work. When clicking on the submit button, I get the decrypted password, and the following as shown in the attached image: Result
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 37013079
Ah yes sorry. Move my code to before the <br>
<form id="form1" name="form1" method="post" action="">
    <p>Encrypted Password:
      <input name="encrypted" maxlength="128" size="50" type="text" id="encrypted" />
&nbsp;&nbsp;&nbsp;<input name="dec" type="submit" id="dec" value="Submit" />
    <br/>      
    <br/>
    Password:
    <input name="decrypted" type="text" size="50" id="decrypted" value="
<?php
  $ok = false;
  $Regex = "/^[A-z0-9]+$/";

  if(isset($_POST['encrypted'])) {
    if(!strlen($_POST['encrypted'])) {
      echo "Input was empty";
      return;
    }
    if(preg_match_all($Regex, $_POST['encrypted'], $Matches)) {
      $command = "./decrypt.pl ".$_POST['encrypted'];
      htmlspecialchars(system($command));
      $ok=true;
    } else {
      echo "Invalid input";
            return;
    }
  }
?>
"/>
<?php 
  if ($ok) {?>
<script type="text/javascript">
window.onload=function() {
  var w = window.open("somepage.html","_blank","width=400,height=400");
  if (!w) alert('Sorry, you have blocked popups')
}
</script>
<?php } ?>
<br>

Open in new window

0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When the s#!t hits the fan, you don’t have time to look up who’s on call, draft emails, call collaborators, or send text messages. An instant chat window is definitely the way to go, especially one like HipChat. HipChat is a true business app. An…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month15 days, 4 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question