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

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.
kosmasAsked:
Who is Participating?
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
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
 
Michel PlungjanIT ExpertCommented:
Add
target="_blank"
To the form tag
0
 
xtermCommented:
Try this:

<form method=post target=_self>
<input type=submit value=Submit onClick="return openWindow('$url',500,300);">
</form>
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
kosmasAuthor Commented:
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
 
xtermCommented:
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
 
Michel PlungjanIT ExpertCommented:
"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
 
Michel PlungjanIT ExpertCommented:
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
 
kosmasAuthor Commented:
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
 
Michel PlungjanIT ExpertCommented:

<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
 
kosmasAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.