2014-09-18 105 views
0

我使用GET方法已經包含像參數中的URL提交表單腓get方法resseting網址

本地主機/ myfile.php?節=控制檯

我的表單代碼

 <form method="GET" action="<?=basename($_SERVER['PHP_SELF'])?>/section=console"> 

      <input type="text" name="cmd" /> 
      <input type="submit" value="execute" /> 
     </form> 

當我通過郵遞方式提交這個數據時,它提交數據然後提交像myfile.php?cmd = blahblah 但我想提交給myfile.php?section = console & cmd = blahblah。

我可以使用隱藏域做到這一點,但我INSEARCH學院的其他更好的辦法

+0

只需將查詢字符串的當前URL作爲表單動作 – 2014-09-18 18:32:16

+0

我沒有明白,請您解釋 – 2014-09-18 18:41:38

+0

爲什麼不使用「/myfile.php?section=console」作爲表單動作? – 2014-09-18 19:50:14

回答

0

你應該用你的表單中的隱藏輸入

<form method="GET" action="<?php echo basename($_SERVER['PHP_SELF']); ?>"> 
    <input type="hidden" name="section" value="console"> 
    <input type="text" name="cmd"> 
    <input type="submit" value="execute"> 
</form> 
+0

我已經在使用這種方法,我只想檢查是否有另一種方法,當我使用POST方法時,我沒有刪除我的部分參數。我想可能還有另一種方法。 – 2014-09-18 18:43:19

+0

@ facebook-100005510415497你仍然可以使用POST並在'myfile.php'中尋找'$ _REQUEST ['section']'而不是get。我不太明白爲什麼隱藏的輸入是不好的? – 2014-09-18 23:13:43

1

只需添加一個隱藏字段到表單

<input type="hidden" name="section" value="console"> 

如果您對使用隱藏字段不感興趣,請重寫您的表單,如下所示

<form method="GET" action="<?php basename($_SERVER['PHP_SELF']) ?>/?section=console">