2017-09-03 126 views
0

我不能为我的生活弄清楚这一点。窗体不发送数据?

我有以下形式,提交时,返回一个空数组? 它在提交时(index.php)进入正确的页面,但它没有传递任何GET或POST。两者都不会使用var_dump($ _ POST)返回任何内容。有任何想法吗?

<form action="index.php" method="post"> 
    <div class="form-group"> 
     <label for="orderName">What is your name?</label> 
     <input type="textbox" class="form-control" id="orderName" aria-describedby="orderName" placeholder="Enter name"> 
    </div> 
    <div class="form-group"> 
     <label for="orderEmail">What is your email address?</label> 
     <input type="textbox" class="form-control" id="orderEmail" aria-describedby="orderEmail" placeholder="Enter email"> 
    </div> 
    <div class="form-group"> 
     <label for="orderCopies">How many copies of the book would you like?</label> 
     <input type="textbox" class="form-control" id="orderCopies" aria-describedby="orderCopies" placeholder="Enter amount of books"> 
     <small id="oderCopiesHelp" class="form-text text-muted">Note: each book is $35 (including postage)</small> 
    </div> 
    <div class="form-group"> 
     <label for="orderAddress">Where would you like the book/s sent to?</label> 
     <textarea class="form-control" id="orderAddress" rows="3"></textarea> 
    </div> 
    <div class="form-group"> 
     <label for="orderComments">Order comments</label> 
     <textarea class="form-control" id="orderComments" rows="3"></textarea> 
    </div>    
    </div> 
    <div class="modal-footer"> 
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> 
    <button type="submit" class="btn btn-primary">Send order</button> 
    </form> 
+0

您的输入标签还应包含PHP数组的名称属性以包含键值。 – Adriani6

回答

4

输入需求name您的标记中缺少的属性。

例如,

<input type="textbox" class="form-control" name="orderName" id="orderName" aria-describedby="orderName" placeholder="Enter name"> 

您的代码与<input><textarea><button>name属性:

<form action="index.php" method="post"> 
    <div class="form-group"> 
     <label for="orderName">What is your name?</label> 
     <input type="textbox" class="form-control" name="orderName" id="orderName" aria-describedby="orderName" placeholder="Enter name"> 
    </div> 
    <div class="form-group"> 
     <label for="orderEmail">What is your email address?</label> 
     <input type="textbox" class="form-control" name="orderEmail" id="orderEmail" aria-describedby="orderEmail" placeholder="Enter email"> 
    </div> 
    <div class="form-group"> 
     <label for="orderCopies">How many copies of the book would you like?</label> 
     <input type="textbox" class="form-control" name="orderCopies" id="orderCopies" aria-describedby="orderCopies" placeholder="Enter amount of books"> 
     <small id="oderCopiesHelp" class="form-text text-muted">Note: each book is $35 (including postage)</small> 
    </div> 
    <div class="form-group"> 
     <label for="orderAddress">Where would you like the book/s sent to?</label> 
     <textarea class="form-control" name="orderAddress" id="orderAddress" rows="3"></textarea> 
    </div> 
    <div class="form-group"> 
     <label for="orderComments">Order comments</label> 
     <textarea class="form-control" name="orderComments" id="orderComments" rows="3"></textarea> 
    </div>    
    </div> 
    <div class="modal-footer"> 
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> 
    <button type="submit" class="btn btn-primary" name="submitButton">Send order</button> 
</form> 
+0

是的。在PHP文件中,你应该执行'$ VarName = $ _POST ['这就是你的输入的名字'];' – Oqhax

+0

然后你可以通过'echo $ VarName'来输出输入。 – Oqhax

+0

Yes .. exactly ... –

0

您需要添加name属性标签为每个输入元素。 name属性和值通过post方法发送给脚本以接收它。

0

对于每个输入标签,始终将name属性传递给表单数据。

Ex。

<input type="textbox" class="form-control" id="orderName" name="orderName" aria-describedby="orderName" placeholder="Enter name">