dtu72460 2016-01-02 15:48
浏览 10

联系表单中的单选按钮,不发送信息[重复]

This question already has an answer here:

I have two radio buttons in my contact form like this:

<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>

and then some generic contact_me.php from the internet like this:

<?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.

"."Here are the details:

Name: $name

Email: $email_address

Phone: $phone

Response: $response

Message:
$message";
/* ... */

But the response-field remains empty always in the email I get, whatever try. I google a lot, nothing helped. I hope you can!

The rest of the code is from template and it works, two radio buttons I added and cannot get to work.

</div>
  • 写回答

1条回答 默认 最新

  • doujiaozhao2489 2016-01-02 16:43
    关注

    I hope you are looking for this:

    Your HTML Form:

    <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>
    

    And PHP Code:

    <?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. 
    
    
    Here are the details: 
    
    
    Name: $name 
    
    
    Email: $email_address 
    
    
    Phone:  $phone 
    
    
    Response: $response 
    
    
    Message: 
     $message";
    
    
    $header = "From: noreply@example.com
    "; 
    $header.= "MIME-Version: 1.0
    "; 
    $header.= "Content-Type: text/html; charset=ISO-8859-1
    "; 
    $header.= "X-Priority: 1
    ";
    
    mail(to, subject, $email_body, $header);
    }
    
    ?>
    

    What I change:

    • Adding proper input names for all field.
    • move success block in else condition
    • add email headers
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大