Link to home
Start Free TrialLog in
Avatar of pmjohnson99
pmjohnson99

asked on

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,

Avatar of minichicken
minichicken

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?
Avatar of pmjohnson99

ASKER

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.

Cool... I am nearly there.... hold on 10 more minutes
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()">
****************************************************
It seems to function, but I am not getting the email, and where do I enter my email so it comes to my email?
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?

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";             ?
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
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.
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");
ASKER CERTIFIED SOLUTION
Avatar of minichicken
minichicken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Let me know if it works....

:)
Hi pmjohnson99

If it worked for you please remember to accept the answer for this question. Thanks :)
One quick thing.  If I press "enter" while inside of the text box I get an error page.  How can I prevent this?