【问题标题】:$_POST array is empty after submitting the from [duplicate]提交 from [重复] 后 $_POST 数组为空
【发布时间】:2019-01-14 00:24:27
【问题描述】:

我有一个简单的表单(如下),我想在电子邮件中发送名称字段但 POST 为空。

HTML 表单:

<form action="contact.php" method="post">
   <div class="form-group">
     <label for="name">Name:</label>
     <input type="text" class="form-control" id="name">
   </div>
   <button type="submit" class="btn btn-default">Submit</button>
</form>

PHP:

<?php
if (isset($_POST['name'])){
    $to = "example@example.com";
    $subject = "Test subject";
    $txt = $_POST['name'];
    $txt .= "test txt";
    $headers = "From: example2@example2.com" . "\r\n" .
    "CC: somebodyelse@example.com";
    if (mail($to,$subject,$txt,$headers)){
        echo "succes";
    }else{
        echo "failed";
    }
} else {
    echo "Name is required!";
}
?> 

有人知道可能出了什么问题吗?我在这台服务器上有其他表单,它们工作正常。

【问题讨论】:

    标签: php html post forms http-post


    【解决方案1】:

    输入必须具有name 属性。

    <input type="text" class="form-control" id="name" name="name">
    

    【讨论】:

    • 天哪....是的,这解决了我的问题,谢谢,我是从引导示例中复制的,没有名称属性。
    • @celodir 确认这是否是正确的答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-25
    • 2010-11-19
    • 2021-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多