Solved

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

Posted on 2004-10-02
15
234 Views
Last Modified: 2006-11-17
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,

0
Comment
Question by:pmjohnson99
  • 9
  • 6
15 Comments
 
LVL 12

Expert Comment

by:minichicken
ID: 12208534
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
 

Author Comment

by:pmjohnson99
ID: 12208625
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
 
LVL 12

Expert Comment

by:minichicken
ID: 12208646
Cool... I am nearly there.... hold on 10 more minutes
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 12

Expert Comment

by:minichicken
ID: 12208702
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
 

Author Comment

by:pmjohnson99
ID: 12208768
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
 
LVL 12

Expert Comment

by:minichicken
ID: 12208804
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
 

Author Comment

by:pmjohnson99
ID: 12208815
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
 
LVL 12

Expert Comment

by:minichicken
ID: 12208842
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
 

Author Comment

by:pmjohnson99
ID: 12208850
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
 
LVL 12

Expert Comment

by:minichicken
ID: 12208867
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
 
LVL 12

Accepted Solution

by:
minichicken earned 125 total points
ID: 12208907
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
 

Author Comment

by:pmjohnson99
ID: 12208949
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
 
LVL 12

Expert Comment

by:minichicken
ID: 12208972
Let me know if it works....

:)
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12209120
Hi pmjohnson99

If it worked for you please remember to accept the answer for this question. Thanks :)
0
 

Author Comment

by:pmjohnson99
ID: 12340427
One quick thing.  If I press "enter" while inside of the text box I get an error page.  How can I prevent this?
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now