联系表格不传递变量

时间:2013-09-12 21:36:06

标签: php forms

我确信我只是错过了一些非常简单的东西,因为我已经从编码中消失了。有人可以发现问题是什么吗?提交时,表单会通过电子邮件发送信息,但电子邮件中不会包含任何变量(如名字,姓氏等)。

我得到的就是这个:

自:
电话: - 回电:
最佳通话时间:
消息:

如果你能找到问题所在 - 我将非常感激。

以下是表单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>

这是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 个答案:

答案 0 :(得分:1)

onSubmit="this.reset();"

您在提交开始时擦除所有数据。

(事件处理程序在事件的正常行为结束之前触发,以便可以取消行为。)

答案 1 :(得分:0)

尝试从表单的属性onSubmit:

中删除“this.reset()”
<form action="mail.php" method="POST" id="main_form" onSubmit="this.reset();">

事件处理程序在执行实际提交操作之前触发。 如果您想在表单提交后在JS中执行某些操作,请查看 this stackoverlow post。它解释了如何在这样做之后提交表单并执行操作。