2011-06-13 143 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