2011-06-13 142 views
3

我想将信息从HTML表单传递到PHP页面。我的问题是,表单中的数据没有被提交。我究竟做错了什么 ?HTML到PHP表单数据未提交

HTML表单

<div id="go"> 
    <form method="get" action="client_authorized.php"> 
     <fieldset> 
      <input type="text" name="query" class="input-text" /> 
      <input type="submit" value="Secure Client Access" class="input-submit" /> 
     </fieldset> 
    </form> 
</div> 

client_authorized.php

<?php 
    print $_GET['query']; 
?> 
+1

为什么你把你的提交按钮放在另一个表单中?当您从该表单提交时,您会丢失以其他表单设置的数据。 – jolt 2011-06-13 14:22:00

回答

4
<div id="go"> 
    <!-- see the moved `target` attribute from other form element to here --> 
    <form target="_blank" method="get" action="client_authorized.php"> 
     <fieldset> 
      <input type="text" name="query" class="input-text" /> 
      <!-- <form target="_blank"> --> 
      <input type="submit" value="Secure Client Access" class="input-submit" /> 
      <!-- </form> --> 
      <!-- this form here is as useless as these comments are, define target in main form --> 
     </fieldset> 
    </form> 
</div> 

Basicly你的第二个<form/>覆盖第一<form/>元素,因此丢失数据。

哦,顺便说一下,PHP的print();不会打印出你的数组数据(至少我认为是这样..),你应该使用print_r();var_dump();来代替。

+1

汤姆照你说的做了。它的工作表示感谢...人为错误总是多余的:) – Vinoth 2011-06-13 14:36:39

+0

我的猜测是@ Michael的解决方案不起作用,因为在'

'元素上丢失了'target'属性。 Altho',并非100%确定。当通过$ _GET而不是$ _POST传递元素时,可能会在PHP_SELF之外发布数据时丢失数据 - 空白窗口。 – jolt 2011-06-13 14:43:50

5

你的提交按钮被包裹在另一个<form>。相反,这应该是<input type='submit'>。只需删除额外的<form></form>。贴的时候

<div id="go"> 
    <form method="get" action="client_authorized.php"> 
    <fieldset> 
     <input type="text" name="query" class="input-text" /> 
     <input type="submit" value="Secure Client Access" class="input-submit" /> 
    </fieldset> 
    </form> 
</div> 
+1

嗨迈克尔...我试过它仍然没有工作。我在其他地方犯了一个错误吗? – Vinoth 2011-06-13 14:25:54

+0

@Vinoth您确定PHP运行正常吗?如果你使用'print_r($ _ GET);'来转储GET变量的内容,你会得到什么? – 2011-06-13 14:30:24