我有一個基本的表單,我正在使用一些基本的PHP提交。我有表單提交工作很好,除了我有一個單選按鈕(用於首選的聯繫方式),我不知道如何將它添加到PHP中,以便在電子郵件中發送。兩個單選按鈕選項都具有相同的名稱,因此該值不起作用。我的代碼如下。使用PHP表單處理的單選按鈕
的PHP如下:
<?php
$name = stripslashes($_POST['name']);
$email = stripslashes($_POST['email']);
$phone = stripslashes($_POST['phone']);
$contact = stripslashes($_POST['contact']);
$message = stripslashes($_POST['message']);
$form_message = "Name: $name \nEmail: $email \nPhone: $phone \nPreferred Method of Contact: $contact \nMessage: $message";
// Exit process if field "human" is filled (because this means it is spam)
if ($_POST['human']) {
echo 'Tastes Like Spam!'; exit; }
// if it is not filled, submit form
else {
header("Location: http://www.newurl.com");
mail("[email protected]", "Email Subject", $form_message, "From: $email");
}
?>
該窗體的HTML低於:
<form method="post" id="form" action="handle_form.php">
<div class="field">
<input type="text" name="human" id="human" class="txt" />
</div>
<div class="field form-inline">
<label class="contact-info" for="txtName">Name*</label>
<input type="text" name="name" id="name" class="txt" value=""/>
</div>
<div class="field form-inline">
<label class="contact-info" for="txtEmail">Email*</label>
<input type="text" name="email" id="email" class="txt" value=""/>
</div>
<div class="field form-inline">
<label class="contact-info" for="txtPhone">Phone</label>
<input type="text" name="phone" id="phone" class="txt" value=""/>
</div>
<div class="field form-inline radio">
<label class="radio" for="txtContact">Preferred Method of Contact</label>
<input class="radio" type="radio" name="contact" checked /> <span>Email</span>
<input class="radio" type="radio" name="contact" /> <span>Phone</span>
</div>
<div class="field form-inline">
<textarea rows="10" cols="20" name="message" id="message" class="txt" value=""></textarea>
</div>
<div class="submit">
<input class="submit" type="submit" name="submit" value="Submit Form">
</div>
</form>
感謝這麼多的幫助!
你也應該在提供輸入ID爲標籤 – 2013-07-17 10:29:27
的屬性更簡單的方法,以標籤的無線電和複選框鏈接是包裝都在一個'