PHP Script needs stay on current page when submitted, and popup a thank you window or other html page

I am working with the following PHP script:

?
 
   $to = "myemail9@anywhere.com";
   $msg = "$name\n\n";
   $msg .="$email\n\n";
   $msg .="$message\n\n";
   

  mail($to, "info email", $msg, "From: My web site\nReply-To: $email\n");
 
?>

and the following html:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="form.php">
  <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

this works so far but:

When submitted the form navigates to a page that is the php form, which is blank and useless.

I want to:

1.  When submitted clear the form
2.  Pop up a new window with a seperate html page in it.
3.  Keep the original window open and on the current page.

I basically want to add my form on my hompage and I don't want to make a whole new page for the form.  I just want to put it at the bottom of my homepage and people can submit their emails and then keep viewing that page.

I could really use some help on this I have gotten the form to go to a new page with "header (location:..)

navigates away from the original page.

thanks for any help,

pmjohnson99Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
minichickenConnect With a Mentor Commented:
If you wish to open any other page in the popup

form.php**************
<?
   $to = "pmjohnson99@yahoo.com";
   $msg = "$_GET[name]\n\n";
   $msg .="$_GET[email]\n\n";
   $msg .="$_GET[msg]\n\n";
   

  mail($to, "info email", $msg, "From: My web site\nReply-To: $GET[email]\n");
 

  //here you can specify the page or url to open, you can create a separate thank you page, and put the path below
  //and you can include the close window button in that thank you page
   header ("Location: thankyou.php");    
   exit;  
?>
0
 
minichickenCommented:
Hi

What do you mean "Pop up a new window with a seperate html page in it". Do you mean when the email form is submitted, you want another popup window with another HTML page and the initial HTML page where is user submits stay the same. So in general when you submits the email form, you will still have the initial HTML page plus the popup window?

Is that correct?
0
 
pmjohnson99Author Commented:
Yes it is exactly.  The new pop up html will be 400 x 400 and say something like thanks and have a close button on it.

0
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
minichickenCommented:
Cool... I am nearly there.... hold on 10 more minutes
0
 
minichickenCommented:
Hi

You will need to use some Javascript for it.
On the popup window I've include both close window link and button, see which one you like.
You will need to use $_GET and not $_POST

Here's the solution, hope it right.... :p

***HTML form***********************************

<html>
<head>

<script language="javascript">
function email_submit()
{
      url = "form.php?email=" + form1.email.value + "&name=" + form1.name.value + "&msg=" + form1.msg.value;
      window.open (url, "mywindow", "width= 400, height= 400");
      form1.reset();
}
</script>

</head>

<body>
<form name="form1" method="post" action="">
  Email:
  <input name="email" type="text" id="email">
  <br>
  Name:
  <input name="name" type="text" id="name">
  <br>
  Message:
  <input name="msg" type="text" id="msg">
  <br>
  <input type="button" name="Button" value="Button" onClick="email_submit()">
</form>

</body>
</html>


***form.php*************************************
<?
   $to = $_GET['email'];
   $msg = "$_GET[name]\n\n";
   $msg .="$_GET[email]\n\n";
   $msg .="$_GET[msg]\n\n";
   

  mail($to, "info email", $msg, "From: My web site\nReply-To: $GET[email]\n");
 
  echo "Thank you $_GET[name]"
 
?>
<br>
<a href="javascript:window.close()">Close window</a>
<br>
<input type="button" name="Button" value="Close window" onClick="window.close()">
****************************************************
0
 
pmjohnson99Author Commented:
It seems to function, but I am not getting the email, and where do I enter my email so it comes to my email?
0
 
minichickenCommented:
How many emails do you want to send out when the form submits?

One to the subscriber and another to yourself?

You can comma separate the emails that you would like to send to
Examples:

$to = "me@home.com, you@school.com, he@lab.com";

or

$to = $_GET['email'] . ", me@home.com";

Is this what you looking for?

0
 
pmjohnson99Author Commented:
just one to myself I have it set up that way, but for some reason am not getting the email.
So it would be:

$to = "pmjohnson99@yahoo.com";             ?
0
 
minichickenCommented:
Hi pmjohnson99

I've just sent you the email from my PC to pmjohnson99@yahoo.com
Check if you received it.

Coz everything works fine my side
0
 
pmjohnson99Author Commented:
yep I got it I am not sure what is going on.  Is this the exact code you posted up above?

I noticed in you html there is nothing connect to the "action" for the form submital.  Should there be?

here is a link of mine:
http://www.roustaboutdesign.com/emailform.htm

check it out.  

Also do you get the "echo" to work also, cause it isn't working on this end.
0
 
minichickenCommented:
The form action="" is correct, as you not using the form to submit, you using the Javascript

I see that you are opening the window with the location "http://www.yahoo.com"

CHANGE
window.open ("http://www.yahoo.com", "mywindow", "width= 400, height= 400");

TO

window.open (url, "mywindow", "width= 400, height= 400");
0
 
pmjohnson99Author Commented:
Okay...now we are talking  it works exactly as I wanted to now.  I have to test this on other servers, but I am sure it will do.

thanks, a lot.
0
 
minichickenCommented:
Let me know if it works....

:)
0
 
minichickenCommented:
Hi pmjohnson99

If it worked for you please remember to accept the answer for this question. Thanks :)
0
 
pmjohnson99Author Commented:
One quick thing.  If I press "enter" while inside of the text box I get an error page.  How can I prevent this?
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.