我正嘗試使用PHP構建自定義搜索表單,並且正在尋找一種將參數追加到URL末尾的方法(基於從選擇框中選擇),然後提交表單。基於選擇框在表單提交時向URL添加參數值
說我有這些值的選擇框: Red Blue Green
如果讓我選擇「藍」並提交表單,我想要的網址是:
http://customsearch.com/result/?Blue
謝謝你任何幫助
我正嘗試使用PHP構建自定義搜索表單,並且正在尋找一種將參數追加到URL末尾的方法(基於從選擇框中選擇),然後提交表單。基於選擇框在表單提交時向URL添加參數值
說我有這些值的選擇框: Red Blue Green
如果讓我選擇「藍」並提交表單,我想要的網址是:
http://customsearch.com/result/?Blue
謝謝你任何幫助
您可以(1)使用JavaScript動態地從表單條目中動態地重寫提交URL(如上面的@roselan所示),(2)實現重寫規則(例如在.htaccess中)或者(3)處理表單字段條目通過POST)在提交頁面,並使用一個簡單的URL重定向像這樣:
/** This is the script the form submits to **/
// Assuming a single dropdown field, set the values of the options to match
// whatever you want sent in the URL, and then submit them via POST.
//
// For a value of "Blue" in the form field where "name='dropdown_name'", the
// following will redirect to:
// http://customsearch.com/result/?Blue
header("Location: http://customsearch.com/result/?" . $_POST['dropdown_name']);
謝謝安德魯,我似乎無法看到Roselan的帖子上面,雖然。我可能最終會做1或3,我有一種感覺,這可能會與htaccess混亂 – rocky