我正在尝试使用PHP构建一个自定义搜索表单,我正在寻找一种方法将参数附加到URL的末尾(基于选择框中的选择),在表单提交时
假设我有一个选择框,它的值如下:Red Blue Green
如果我选择"蓝色"并提交表单,我希望URL为:
http://customsearch.com/result/?Blue
感谢您的帮助
那么你需要$_GET[]
和。htaccess的混合物
您可以(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'] );