2014-06-28 71 views
-1

請幫助這個情況:我有與類型「單選」評級按鈕簡單的反饋形式:如何從php反饋表單中獲取radiobuttons組的數據?

<form action="php/feedback.php" method="post"> 
<input type="text" class="form-control" id="exampleInput2" placeholder="Name and Surname)" name="q4" required> 
<p>Please, rate us!</p> 
<label class="radio-inline"><input type="radio" id="inlineRadio1" value="1" name="q5_1"> 1 </label> 
<label class="radio-inline"><input type="radio" id="inlineRadio2" value="2" name="q5_2"> 2 </label> 
<label class="radio-inline"><input type="radio" id="inlineRadio3" value="3" name="q5_3"> 3 </label> 
<label class="radio-inline"><input type="radio" id="inlineRadio4" value="4" name="q5_4"> 4 </label> 
<label class="radio-inline"><input type="radio" id="inlineRadio5" value="5" name="q5_5"> 5 </label> 
</form> 

而且我的PHP代碼:

<? 
$adminemail="[email protected]"; 
$date=date("d.m.y"); 
$time=date("H:i"); 
$backurl="http://test.mymail"; 
$q4=$_POST['q4']; 
if ($_POST['q5_1']==="1") echo $q5_1=$_POST['q5_1']; 
if ($_POST['q5_2']==="2") echo $q5_1=$_POST['q5_2']; 
if ($_POST['q5_3']==="3") echo $q5_1=$_POST['q5_3']; 
if ($_POST['q5_4']==="4") echo $q5_1=$_POST['q5_4']; 
if ($_POST['q5_5']==="5") echo $q5_1=$_POST['q5_5']; 
{ 
$msg=" 
Name: $q4 
Rate: $q5_1 $q5_2 $q5_3 $q5_4 $q5_5 
"; 
mail("$adminemail", "$date $time Feedback from $q4", "$msg" ,"Content-type:text/plain; charset=utf-8"); 
print "<script language='Javascript'><!-- function reload() {location = \"$backurl\"}; setTimeout('reload()', 2000); //--></script> 
<p>Redirecting....</p>"; 
exit; 
} 
?> 
從單選按鈕

和數據不輸入消息。我不知道如何使它工作。謝謝你的幫助!

+0

你的單選按鈕應該有同等'很多語法錯誤name'屬性('name =「q5」') - 然後,在提交時,值將被附加到該名稱。 (也就是說,根據所選按鈕,'$ _POST [「q5」]'將會是'1,2,3,4'或'5')。 – dognose

+0

@dognose謝謝!具有不需要的'{'和'}'的 – OlegGerasimenko

回答

0

您需要將數據提交給您php頁面,無論是與ajax或簡單input標籤與type='submit',你也有你的php代碼

<?php 
if(POST_['submit']){ //to make sure data was actually sent from the page 
$adminemail="[email protected]"; 
$date=date("d.m.y"); 
$time=date("H:i"); 
$backurl="http://test.mymail"; 
$q4=$_POST['q4']; 
if ($_POST['q5_1']=="1"){ echo $q5_1=$_POST['q5_1'];} 
if ($_POST['q5_2']=="2"){ echo $q5_1=$_POST['q5_2'];} 
if ($_POST['q5_3']=="3"){ echo $q5_1=$_POST['q5_3'];} 
if ($_POST['q5_4']=="4"){ echo $q5_1=$_POST['q5_4'];} 
if ($_POST['q5_5']=="5"){ echo $q5_1=$_POST['q5_5'];} 
//{ not sure why this was here 
$msg=" 
Name: $q4 
Rate: $q5_1 $q5_2 $q5_3 $q5_4 $q5_5 
"; 
mail("$adminemail", "$date $time Feedback from $q4", "$msg" ,"Content-type:text/plain; charset=utf-8"); 
print "<script language='Javascript'><!-- function reload() {location = \"$backurl\"}; setTimeout('reload()', 2000); //--></script> 
<p>Redirecting....</p>"; 
exit; 
//} or this 
} //end of submit post 
?> 
+0

不是語法錯誤。他們不是必需的,但並沒有錯。 – dognose

+0

使組織代碼更好,我知道這不是必需的。但整齊的代碼是快樂的代碼 –