2016-12-25 75 views
1

我有這種形式發送查詢到同一頁面

<form action="index.php?store=<?php echo $_GET['store'];?>/" method="GET"> 
     <input type="text" class="form-control txt-fc" name="s" placeholder="Enter Product Name" /> 
</form> 

當前頁面的URL是這樣

index.php?store=gsStore 

現在的問題是,當我提交表單的URL變成這樣

index.php?s=Graphics+Cards 

由於在URL中有store因此PHP顯示錯誤!我真正想要的是,它應提交表單不失store變量這樣

index.php?store=gsStore&s=Graphics+Cards 

它是如何是可以實現的?

回答

3

使用隱藏的輸入元素:

<form action="" method="GET"> 
    <input type="hidden" name="store" value="<?php echo $_GET['store'];?>"> 
    <input type="text" class="form-control txt-fc" name="s" placeholder="Enter Product Name" /> 
</form> 
+0

要老實跟你說......我用這一招使用'hidden'場了很多次......這一次沒來了我的心。謝謝你的答案:)將接受無損時間罰款完成 –

+0

你應該考慮轉義任何不需要的HTML標記,以避免GET漏洞。 –

+0

@AlexShifu如果用戶關注沒有存儲參數的鏈接,會發生什麼情況?我認爲你應該在PHP中處理它,並將用戶重定向到默認存儲區,或者在代碼中放置默認存儲區參數而不是GET ['store'](如果它爲空)。想想看。 很高興聽到它有幫助。 – smozgur

相關問題