2014-01-08 53 views
0

我使用隱藏的輸入類型來隱藏URL中的數據。這裏是我的代碼獲取值表單輸入類型隱藏

<input type="hidden" name="post_type" value="kcc-product"> 
<input type="hidden" name="post_type" value="kcc-manufacturer"> 

當我使用它,我收到網址爲&post_type=kcc-product&post_type=kcc-manufacturer

但我需要它像:&post_type=kcc-product&kcc-manufacturer

只是我必須從URL中移除**post_type=**。我試過

<input type="hidden" name="post_type" value="kcc-product"> 
<input type="hidden" name="" value="kcc-manufacturer"> 

但是,它不工作。我如何從URL中刪除**post_type=**?有任何想法嗎?

+0

你可以住'post_type = kcc-product,kcc-manufacturer'嗎?你應該花一點時間看看@表單提交是如何工作的以及如何格式化URL查詢字符串。你也可以做一些事情,比如'kcc-product =&kcc-manufacturer ='。 –

+0

使用POST !!!!!!! –

+0

要得到一個像你這樣的URL,你需要一個名爲'kcc-manufacturer'的表單域(隱藏或不隱藏),沒有任何價值。這可能不是你想要的。所以,我建議重新評估你需要什麼以及如何在服務器上使用提交的值。你可以使用jQuery來「組裝」URL,但是,如果你期待這個值,你必須在服務器上做錯了什麼。 – Floremin

回答

0
<input type="hidden" name="post_type[]" value="kcc-product"> 
<input type="hidden" name="post_type[]" value="kcc-manufacturer"> 

試試這個。這兩個post_type的值都可以作爲數組在$_GET['post_type']中使用。

+0

是的,這個完美的工作。 –

0

這並不是說我提倡這種做法,但..

你爲什麼不只是有一個隱藏字段變量,而不是兩者兼而有之?

<input type="hidden" name="post_type" value="kcc-product&amp;kcc-manufacturer"> 

這會產生你是經過「& post_type = KCC產品& KCC-製造商」

+0

當我使用一個像這樣的隱藏字段時,它不會在URL中生成&符號。 '' 它顯示爲:&post_type = kcc-product%26kcc-製造商 我的意思是生成%26而不是&符號。 –

+0

對不起,它不是在URL中生成符號。使用您的代碼,它正在生成&post_type = kcc-product%26kcc-製造商 –

0

的第一件事是,不應該是兩個具有相同名稱的隱藏字段的URL。 因此,您可以刪除一個額外的隱藏字段,並將它們組合爲一個。然後寫如下:

<input type="hidden" name="post_type" value="kcc-product&kcc-manufacturer"> 

否則,如果您使用兩個隱藏字段,它認爲作爲兩個單獨的參數,並顯示爲兩個單獨的參數。

否則在form標籤中指定method =「POST」,它將自動不會在url中顯示。

我想,這可能會有所幫助。

+0

對不起,它正在生成&post_type = kcc-product%26kcc-製造商 否符號,只在URL中生成%26。 –

+0

在form標籤中指定method =「POST」 – venky

+0

我使用了method =「POST」,但不工作。 –