PHP没有从HTML5表单接收数据

时间:2015-11-12 09:52:58

标签: php html5 html-form-post

我最近进入了php并在Xampp本地运行它。我创建了以下简单的表单,然后是几行php。似乎没有数据从html表单传递到php页面。

<form method="post" action="emailform.php" enctype="text/plain" class="form-horizontal">
    <div class="row input">
        <div class="col-md-1"></div>
        <div class="col-md-10">
            <div class="form-group">
                <input type="text" name="subject" id="subject" class="form-control" placeholder="subject">
            </div>
        </div>
    </div>
    <div class="row input">
        <div class="col-md-1"></div>
        <div class="col-md-4">
            <div class="form-group">
                <input type="text" name="name" id="name" class="form-control" placeholder="full name">
            </div>
            <div class="form-group">
                <input type="email" name="subject" id="email" class="form-control" placeholder="email">
            </div>
        </div>
        <div class="col-md-1"></div>
        <div class="col-md-5 textarea">
            <textarea class="form-control" name="message" id="message" rows="4" placeholder="message"></textarea>
        </div>
    </div>
    <br>
    <div class="row">
        <div class="col-md-1"></div>
        <div class="col-md-10">
            <button type="submit" class="btn" id="submit">Send</button>
        </div>
    </div>
</form>

这是我用来测试的简单php代码:

<?php            
        $subject = 'No subject was set';
        if (isset($_POST['subject'])) {
            $subject = ($_POST['subject']);
        }
        echo "This is the subject:$subject"; 
    ?>

我感谢任何帮助,因为我过去一周一直在努力使用这个简单的代码。

1 个答案:

答案 0 :(得分:1)

两个主题名称!

<input type="email" name="subject" id="email" class="form-control" placeholder="email">
                          ^

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

同时从表单

中删除enctype="text/plain"

这是因为PHP doesn't handle it