0

I'm sure I'm just missing something really simple, because I'm burned out from coding. Can someone please spot what the problem is? When submitted the form emails the info, but none of the variables (like firstname, lastname, etc) are being included in the email.

All I get is this:

From:
Phone: -- Call Back:
Best time to call:
Message:

If you can find what the problem is - I will be very thankful.

Here is the form HTML:

<form action="mail.php" method="POST" id="main_form" onSubmit="this.reset();">
<p>First Name</p> <input type="text" name="firstname" size="93" style="width:475px; float:left;"><br />
<p>Last Name</p> <input type="text" name="lastname" size="93" style="width:475px; float:left;"><br />
<p>Email</p> <input type="text" name="email" size="93" style="width:475px; float:left;"><br />
<p>Confirm E-mail</p> <input type="text" name="confirmemail" size="93" style="width:475px; float:left;"><br />
<p>Contact Number<br />
<input type = "text" id = "Ph1" name="Ph1" size =" 3" maxlength = "3" onkeyup = "validate(this,2)">-
<input type = "text" id = "Ph2" name="Ph2" size =" 3" maxlength = "3" onkeyup = "validate(this,3)">-
<input type = "text" id = "Ph3" name="Ph3" size =" 4" maxlength = "4" onkeyup = "validate(this,3)">
</p>
<script type = "text/javascript">
function validate(which,next) {
var val = which.value;
val = val.replace(/[^0-9]/g,"");  // strip non-digits
which.value = val;
next = "Ph" + next;
if (val.length == 3) {  // field completed
document.getElementById(next).focus()
}
}
</script>

<p>Request Phone Call:<br />
<span style="font-family:'Open Sans', serif; font-size:14px;">Yes:</span><input type="radio" value="Yes" name="call">
<span style="font-family:'Open Sans', serif; font-size:14px;">No:</span><input type="radio" value="No" name="call"><br />
</p>
<p>Best time to contact:<br />
<span style="font-family:'Open Sans', serif; font-size:14px;">Morning:<input type="radio" value="Morning" name="calltime">
<span style="font-family:'Open Sans', serif; font-size:14px;">Afternoon:<input type="radio" value="Afternoon" name="calltime">
<span style="font-family:'Open Sans', serif; font-size:14px;">Evening:<input type="radio" value="Evening" name="calltime"><br />
</p>
<p>Message</p><textarea name="message" rows="6" cols="67"></textarea><br />
<input class = "_submit"type="submit" value="SUBMIT" style="width: 128px;
height: 36px;
font-family: 'Pathway Gothic One', serif;
font-size: 28px;
border-radius: 0px;
border-width: 0px;
color: #FFF;
background-color: #FFCA04; float:left; margin-top: 10px;">
</form>

Here is the mail.php

<?php
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$confirmemail = $_POST['confirmemail'];
$phone1 = $_POST['Ph1'];
$phone2 = $_POST['Ph2'];
$phone3 = $_POST['Ph3'];
$call = $_POST['call'];
$calltime = $_POST['calltime'];
$message = $_POST['message'];
$formcontent=" From: $firstname $lastname \n Phone: $phone1-$phone2-$phone3 \n Call Back: $call \n Best time to call: $calltime \n Message: $message";
$recipient = "MyEmail@domain.com";
$subject = "YOU HAVE A MESSAGE FROM WEBSITE CONTACT PAGE";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='form.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>

2 Answers2

1
onSubmit="this.reset();"

You wipe all the data when the submission begins.

(Event handlers fire before the normal behaviour of an event resolves so that behaviour can be cancelled).

Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205
0

Try removing "this.reset()" from form's attribute onSubmit:

<form action="mail.php" method="POST" id="main_form" onSubmit="this.reset();">

Event handlers fire before taking actual submit action. If you want to do something in JS after form submission, take a look at this stackoverlow post. It explains how to submit form and perform actions after doing so.

Community
  • 1
  • 1
Kleskowy
  • 2,578
  • 1
  • 14
  • 18
  • Thanks. That worked. Is there an easy way to clear the form after submission? – rockandrollnerd Sep 12 '13 at 23:40
  • I updated my answer - it now has a link to explanation how to clear the form or how to perform any other task in JS AFTER submitting a form - check it out – Kleskowy Sep 14 '13 at 15:48