[英]contact form missing fields in email
I am having a problem getting two variables to be sent from my contact form. 我在从联系表格发送两个变量时遇到问题。 when the form submits, I get all the fields except these which are empty searchType: date. 当表单提交时,我得到了除这些空的searchType:date以外的所有字段。 I think I may have missed something but can not see what does anyone have any idea? 我想我可能错过了一些东西,但是看不到有人对它有什么想法? I am also using javascript to create a cascading dropdown effect so that the dates are dependant on the course selected. 我还使用javascript创建级联下拉效果,以便日期取决于所选课程。
<label for="training">What kind of training?</label>
<select id="searchType" class="fixed-size-drop">
<option value="sessions">Introduction to Marketing</option>
<option value="files">Social Media Workshop</option>
<option value="clients">Advanced Marketing Workshop</option>
<option value="firstaid">First Aid Training</option>
</select>
<label for="date">Choose your Date:</label>
<select id="sessions" class="fixed-size-drop2">
<option value="020914">2nd sept 2014</option>
<option value="18_sept_14">18th sept 2014</option>
</select>
<select id="files" class="fixed-size-drop2">
<option value="11_sept_14">11th sept 2014</option>
<option value="18_sept_14">18th sept 2014</option>
</select>
<select id="clients" class="fixed-size-drop2">
<option value="9_sept_14">9th sept 2014</option>
<option value="25_sept_14">25th sept 2014</option>
</select>
<select id="firstaid" class="fixed-size-drop2">
<option value="03_sept_14">3rd September 2014</option>
<option value="16_sept_14">16th September 2014</option>
</select>
</div>
<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){
// all your form processing code goes in here, including the mail() statement.
$EmailFrom = "$name";
$EmailTo = "email@email.co.uk";
$Subject = "Online contact form";
$name = trim(stripslashes($_POST['name']));
$companyname = trim(stripslashes($_POST['companyname']));
$position = trim(stripslashes($_POST['position']));
$email = trim(stripslashes($_POST['email']));
$phone = trim(stripslashes($_POST['phone']));
$searchType = trim(stripslashes($_POST['searchType']));
$sessions = trim(stripslashes($_POST['sessions']));
$newsletter = trim(stripslashes($_POST['newsletter']));
// prepare email body text
$Body = "";
$Body .= "name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "companyname: ";
$Body .= $companyname;
$Body .= "\n";
$Body .= "position: ";
$Body .= $position;
$Body .= "\n";
$Body .= "email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "searchType: ";
$Body .= $searchType;
$Body .= "\n";
$Body .= "sessions: ";
$Body .= $sessions;
$Body .= "\n";
$Body .= "newsletter: ";
$Body .= $newsletter;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: $EmailFrom");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.domain.co.uk/thankyou.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=http://www.domain.co.uk/error.html\">";
}
}
?>
You need to put the name
attribute on your select
elements. 您需要将name
属性放在select
元素上。 This is the attribute which defines the name in the $_POST
array. 这是定义$_POST
数组中名称的属性。
eg 例如
<select id="sessions" class="fixed-size-drop2" name="sessions">
Your fields should have a name property for PHP to receives them Your select element is missing the name property: 您的字段应具有供PHP接收的name属性,您的select元素缺少name属性:
<select id="searchType" class="fixed-size-drop">
should be 应该
<select id="searchType" name="searchType" class="fixed-size-drop">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.