Forum Moderators: open

Message Too Old, No Replies

Submit Button

how do i use a submit button to email info & send user to thankyou page?

         

laurasamps

10:32 am on May 4, 2010 (gmt 0)

10+ Year Member



Hi, im an extreme novice so please be gentle!

I have so far learnt how to create a form, but I need the submit button to both send the entered information to my email address, and also redirect the user to a thank you page.

Am I correct in thinking that the following script sends the info to my email:

<form action="mailto:you@youraddress.com"> ?

and is placed within the form?

So far this does not seem to have worked..

Also how do I then send them to a thank you page?

i.e two actions within the one submit button..

I know the answers probably simple but its not for me!

Thank you very much!

Fotiman

12:48 pm on May 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Welcome to WebmasterWorld!

You'll want to address this with some sort of server side processing, like PHP or ASP. The problem with using "mailto:..." is that it will try to open the default email client on the user's computer. But today many users no longer even use a client application for email. Many users use some form of webmail, like GMail, Hotmail, etc. For those users, this approach will not work.

Also, as you've discovered, there isn't a way to redirect to a "thank you" page with the "mailto:..." approach.

Instead, you would want the form to submit to some page on the server which would handle the email and redirection. In which case, this is not really a JavaScript question. I'm sure that's probably not the answer you were hoping for, but I hope this info is still helpful.

laurasamps

1:29 pm on May 4, 2010 (gmt 0)

10+ Year Member



To be honest, I have no idea what you just said! I'm going to try and find the right place to post my question as I dont understand PHP either.

Thanks very much

Fotiman

2:12 pm on May 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'll try and clarify a little.

You would do something like this:

<form action="emailAndThanks.php">
<div>
<input name="fromEmail" ...>
<textarea name="message" ...></textarea>
</div>
</form>

The user would enter his/her message in a form, then the form would submit to some PHP page. That PHP page would take that message and email it to you (this has the added benefit of keeping your email address private, which will reduce spam). Then that PHP page would display the "thank you" message.

laurasamps

3:04 pm on May 4, 2010 (gmt 0)

10+ Year Member



ok so all that goes on my page that contains my form...in a HTML page..

and the submit button redirects the user to a php page called emailAndThanks? that page contains a php script which captures their info and displays a thank you message?

Sorry for being slow, im grateful for your help!

Fotiman

4:32 pm on May 4, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, that is correct. :)

laurasamps

8:47 am on May 5, 2010 (gmt 0)

10+ Year Member



Ok I thought I was there...but it seems Im not..

I have this is my main page:


<body>
<form action="emailAndThanks.php" method="post">
<div>
<table width="50%" border="1">
<tr>
<td><label for="name">Name:</label></td>
<td><input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td><label for="company">Company:</label></td>
<td><input type="text" name="company" id="company" /></td>
</tr>
<tr>
<td><label for="postion">Position:</label></td>
<td><input type="text" name="postion" id="postion" /></td>
</tr>
<tr>
<td><label for="phone">Phone Number:</label></td>
<td><input type="text" name="phone" id="phone" /></td>
</tr>
<tr>
<td><label for="email">E-Mail Address:</label></td>
<td><input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td><label for="requirements">Requirements:</label></td>
<td><textarea name="requirements" id="requirements" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label for="button"></label>
<input type="submit" name="button" id="button" value="Submit" /></td>
</tr>
</table>
</div>
</form>

</body>
</html>


And this in my emailandthanks.php page:

<body>
<?php
$to = "#*$!@btinternet.com";
$name = $_POST['name'];
$company = $_POST['company'];
$position = $_POST['position'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$requirements = $_POST['requirements'];
$d = date('l dS \of F Y h:i:s A');
$sub = "form to mail";
$headers = "From: $name <$email>\n";
$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";
$mes = "Subject: ".$subject."\n";
$mes .= "Message: ".$msg."\n";
$mes .= "Name: ".$name."\n";
$mes .= 'Email: '.$email."\n";
$mes .= 'Date & Time: '.$d;

if (empty($name) ¦¦ empty($email) ¦¦ empty($phone) ¦¦ empty($requirements))
{
echo " <h3>Sorry all fields are required.</h3>";
}
?>


When I preview the first page in firefox to see how it works, I click the submit button of the form and it brings up a file download box asking if i want to save or open the emailandthanks.php, i do not want my customers to do have to do this obviously, I just want the smooth transition. Can you *or anyone else* see what I am missing please?

Thank you very much


</body>
</html>

Fotiman

12:57 pm on May 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$headers .= "Content-Type: text/plain; charset=iso-8859-1\n";


Try using a content type of "text/html"

laurasamps

1:09 pm on May 5, 2010 (gmt 0)

10+ Year Member



nope, still brings up the download file box..

Fotiman

1:13 pm on May 5, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is your server configured with PHP? This sounds like what I would expect to happen if PHP was not running on the server.