我不能为我的生活弄清楚这一点。
我有以下表单,提交时返回一个空数组? 它在提交时会转到正确的页面(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 :(得分:4)
输入需要name
属性,标记中缺少该属性。
例如,
<input type="textbox" class="form-control" name="orderName" id="orderName" aria-describedby="orderName" placeholder="Enter name">
name
,<input>
和<textarea>
上包含<button>
个属性的代码:
<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>
答案 1 :(得分:0)
您需要为每个输入元素添加名称属性标记。 name属性和值通过post方法发送到脚本以接收它。
答案 2 :(得分:0)
对于每个输入标记,始终使用name属性来传递表单数据。
实施例
<input type="textbox" class="form-control" id="orderName" name="orderName" aria-describedby="orderName" placeholder="Enter name">