在POST上无法将html表的内容作为表单数据传递?

时间:2016-06-14 09:15:22

标签: php html forms html-table

我有一张表,代码如下, 该表有select和checkbox,我尝试将表包装在一个表单中并发布到results.php以回显, 但是在提交表格时,它不起作用。如何从results.php获取复选框选中的值?

<script>   
var currentSelected = "";
var currentItem = "";
function show(obj, item) {   
if (currentSelected != "" && currentSelected != obj) {
    currentSelected.checked = false;
    document.getElementById(currentItem).style.display = currentSelected.checked ? "block" : "none"; 

}
document.getElementById(item).style.display = obj.checked ? "block" :"none";
currentSelected = obj;
currentItem = item;
}
</script>
<form action="results.php" method="post">
    <table width="805" border="0" >
        <tr>
          <td width="30">&nbsp;</td>
        <td width="30">&nbsp;</td>
        <td width="30">&nbsp;</td>
        <td width="30">&nbsp;</td>
        <td width="38">&nbsp;</td>
        <td width="25">&nbsp;</td>
        <td width="114">&nbsp;</td>
        <td width="456">&nbsp;</td>
      </tr>
        <tr>
          <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
        <tr>
          <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>Range</td>
        <td>&nbsp;</td>
        <td><p>
            <input type="checkbox" name="absolute" onChange="change(this)"  onclick="show(this,'s1');">
            Absolute</p>
          <p>&nbsp;</p>
            <p>
            <input type="checkbox" name="quick" onChange="change(this)" onclick="show(this,'s2');">
            Quick</p></td>
        <td><p>
         <div id="s1" style="display:none">
            <input class="date" id="datepicker" type="text" value="" name="from"  placeholder="From" onFocus="this.value = '';" onBlur="if (this.value == '') {this.value = '';}" required=>
            <input class="date" id="datepicker1" type="text" value="" name="to" placeholder="To" onFocus="this.value = '';" onBlur="if (this.value == '') {this.value = '';}" required=>
            </div>
          </p>
          <p>&nbsp;</p>
            <p>
            <div id="s2" style="display:none">
            <select name="quickselect" id="quickselect"  >
                <option value="30">Last 30 minutes</option>
                <option value="60">Last 1 hour</option>
                <option value="4h">Last 4 hour</option>                 
              </select>
              </div>
          </p></td>
      </tr>
        <tr>
          <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
        <tr>
          <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>Location</td>
        <td>&nbsp;</td>
        <td colspan="2">
       </td>
      </tr>
        <tr>
          <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>Index</td>
          <td>&nbsp;</td>
          <td colspan="2"><select name="loc" id="locselect" >
            <option value="la">LA</option>
            <option value="ny">NY</option>
            <option value="all">CA & NY </option>
          </select></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;</td>
      </tr>
       <tr>
          <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>Keyword</td>
        <td>&nbsp;</td>
        <td colspan="2">
          <input type="text" name="keyword" id="keyword" width="200">
        </span></td>
      </tr>
        <tr>
          <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="3"><div class="bnr-btn">
          <input type="submit" value="Search">
          </div></td>
      </tr>
      </table>
      </form>

results.php

 <?php
   //how to echo the checkbox value ?????????

   $quickselect= $_POST["quickselect"];
   $locselect =$_POST["locselect "];
   $keyword = $_POST["keyword "];
  ?>

2 个答案:

答案 0 :(得分:0)

要使用PHP从POST请求中检索值,您可以使用类似这样的内容

$checkbox = $_POST['absolute'];

参数名称和值与html标签上的相同。

例如:

<input name="absolute" type="checkbox" value="Your value" />

答案 1 :(得分:0)

表示复选框:

$checkbox1=$_POST['absolute'];
$checkbox2=$_POST['quick'];

获取日期值

$from=$_POST['from'];
$to=$_POST['to'];