2016-01-02 85 views
-2

我有我的聯繫方式是這樣兩個單選按鈕:單選按鈕,不發送信息

<div class="field form-inline radio"> 
    <input class="radio" type="radio" name="response" value="ATTENDING" /><span>Blalala 1</span> 
</div> 
<div class="field form-inline radio"> 
    <input class="radio" type="radio" name="response" value="NOT ATTENDING" /><span>Blablabla 2</span> 
</div> 

/* ... */ 

<div class="form-group col-xs-12 floating-label-form-group controls"> 
    <label>Name</label> 
    <input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Write your name"> 
    <p class="help-block text-danger"></p> 
    </div> 

,然後從互聯網上一些通用的contact_me.php這樣的:

<?php 
// Check for empty fields 
if(empty($_POST['name']) || 
empty($_POST['email']) || 
empty($_POST['phone']) || 
empty($_POST['message']) || 
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) 
{ 
echo "No arguments Provided!"; 
return false; 
} 

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 
$phone = $_POST['phone']; 
$response = $_POST['response']; 

/* ... */ 
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nResponse: $response\n\nMessage:\n$message"; 
/* ... */ 

但是無論怎樣嘗試,總是在我收到的電子郵件中響應字段始終爲空。我谷歌很多,沒有任何幫助。我希望你可以!

其餘的代碼是從模板,它的工作原理,我添加了兩個單選按鈕,無法工作。

+0

什麼的var_dump($ _ POST);說(把它放在$ email_body之前)?收音機在

elemenet裏面? –

+0

你使用哪種形式的方法?你可以加 – devpro

+0

並在其他條件下添加你的成功塊 – devpro

回答

0

我希望您正在尋找這樣的:

HTML表單:

<form method='post' action=''> 
<input type="text" name="name" value=""> 
<input type="text" name="email" value=""> 
<input type="text" name="phone" value=""> 
<input type="text" name="message" value=""> 
<input type="radio" name="response" value="Attend">Attend 
<input type="radio" name="response" value="Not Attend">Not Attend 

<input type="submit" name="submit" value="Submit"></form> 

和PHP代碼:

<?php 
// Check for empty fields 
if(empty($_POST['name']) || 
empty($_POST['email']) || 
empty($_POST['phone']) || 
empty($_POST['message']) || 
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) 
{ 
echo "No arguments Provided!"; 
return false; 
} 
else { 

$name = $_POST['name']; 
$email_address = $_POST['email']; 
$message = $_POST['message']; 
$phone = $_POST['phone']; 
$response = $_POST['response']; 

/* email body */ 
$email_body = "You have received a new message from your website contact form. \n\n 
Here are the details: \n\n 
Name: $name \n\n 
Email: $email_address \n\n 
Phone: $phone \n\n 
Response: $response \n\n 
Message: \n $message"; 


$header = "From: [email protected]\r\n"; 
$header.= "MIME-Version: 1.0\r\n"; 
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
$header.= "X-Priority: 1\r\n"; 

mail(to, subject, $email_body, $header); 
} 

?> 

我改變什麼:

  • 爲所有字段添加適當的輸入名稱。在其他條件
  • 此舉成功塊
  • 添加電子郵件標題