?
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
Medium Priority
?
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 375 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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

743 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