2014-04-16 327 views
0

我正在建立电子邮件表格。在此电子邮件的形式,有一个星评级,单选按钮:通过电子邮件发送评价

<span class="star-rating"> 
    <input type="radio" name="rating" id="rating" value="1"><i></i> 
    <input type="radio" name="rating" id="rating" value="2"><i></i> 
    <input type="radio" name="rating" id="rating" value="3"><i></i> 
    <input type="radio" name="rating" id="rating" value="4"><i></i> 
    <input type="radio" name="rating" id="rating" value="5"><i></i> 
</span> 

如果我的形式发送到我的邮箱地址,它让我看到星级空。

下面是代码来获得等级:

$rating = $_Post['rating']; 

这是全码:

<?php 

if(isset($_POST['email']) or isset($_POST['first_name']) or isset($_POST['last_name']) or isset($_POST['subject']) or isset($_POST['message']) or isset($_POST['rating'])) { 



    // Mediatube Contact Informations 

    $email_to = "[email protected]"; 

    $email_subject = "Contact to [email protected]"; 





    function died($error) { 

     // your error code can go here 

     echo "We are very sorry, but there were error(s) found with the form you submitted. "; 

     echo "These errors appear below.<br /><br />"; 

     echo $error."<br /><br />"; 

     echo "Please go back and fix these errors.<br /><br />"; 

     die(); 

    } 



    // validation expected data exists 

    if(!isset($_POST['email']) || 

     !isset($_POST['first_name']) || 

     !isset($_POST['last_name']) || 

     !isset($_POST['subject']) || 

     !isset($_POST['message']) || 

     !isset($_POST['rating'])) { 

     died('We are sorry, but there appears to be a problem with the form you submitted.');  

    } 


    $email = $_POST['email']; // required 

    $first_name = $_POST['first_name']; // required 

    $last_name = $_POST['last_name']; // required 

    $subject = $_POST['subject']; // required 

    $message = $_POST['message']; // required 

    $rating = $_Post['rating']; // required 



    $error_message = ""; 

    $email_exp = '/^[A-Za-z0-9._%-][email protected][A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; 

    if(!preg_match($email_exp,$email)) { 

    $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; 

    } 

    $string_exp = "/^[A-Za-z .'-]+$/"; 

    if(!preg_match($string_exp,$first_name)) { 

    $error_message .= 'The First Name you entered does not appear to be valid.<br />'; 

    } 

    if(!preg_match($string_exp,$last_name)) { 

    $error_message .= 'The Last Name you entered does not appear to be valid.<br />'; 

    } 

    if(strlen($message) < 2) { 

    $error_message .= 'The Message you entered do not appear to be valid.<br />'; 

    } 

    if(strlen($error_message) > 0) { 

    died($error_message); 

    } 

    $email_message = "Email sent by Email Form at Mediatube.\n\n"; 



    function clean_string($string) { 

     $bad = array("content-type","bcc:","to:","cc:","href"); 

     return str_replace($bad,"",$string); 

    } 


    $email_message .= "Email: ".clean_string($email)."\n"; 

    $email_message .= "First Name: ".clean_string($first_name)."\n"; 

    $email_message .= "Last Name: ".clean_string($last_name)."\n"; 

    $email_message .= "Subject: ".clean_string($subject)."\n"; 

    $email_message .= "Message: ".clean_string($message)."\n"; 

    $email_message .= "Rating: ".clean_string($rating)."\n"; 





// create email headers 

$headers = 'From: '.$email."\r\n". 

'Reply-To: '.$email."\r\n" . 

'X-Mailer: PHP/' . phpversion(); 

@mail($email_to, $email_subject, $email_message, $headers); 

?> 



<!-- html success code --> 



Thank you for contacting us. We will be in touch with you very soon. 



<?php 

} 

?> 

什么是错的,我该怎么办?

感谢您的回复!

+3

没有''_Post'这样的事情,除非你自己创建。 – PeeHaa

+0

将$ _Post更改为$ _POST,将名称等级更改为rating [],并且不能使用相同ID的多个元素,请将其更改为 – Pwner

回答

1

我们的代码有很多错误。

你不能有多个同名的ids,所以你必须改变它。

而且你的代码

$rating = $_Post['rating']; 

变化

$rating = $_POST['rating']; 
0

大写POST,因为我认为区分大小写。

$rating = $_POST['rating']; 

假设这些输入正确包裹在其中被发布到一个单独的PHP页面的表单只是echo $rating;,并确保你有正确的值。可以在PHP POST函数here上找到更多信息。

也无关 - 正如@Pwner补充说的。你没有多个具有相同ID的元素,为了设计你应该使用CSS类的样式。了解更多关于ID与类here

+0

谢谢您的回复! – user3535654

+0

我假设你的表单是用'method =“POST”'设置的?然后'var_dump($ rating);'在你的表单发布到的页面上,让我知道响应。 –

+0

很高兴我能帮到你。如果此答案正确或导致您修复代码,请将其标记为答案。 –

0

我改变了这种代码

$rating = $_Post['rating']; 

这个代码

$rating = $_POST['rating']; 

现在它工作:)