2011-11-02 23 views
1

我正尝试使用PHP构建自定义搜索表单,并且正在寻找一种将参数追加到URL末尾的方法(基于从选择框中选择),然后提交表单。基于选择框在表单提交时向URL添加参数值

说我有这些值的选择框: Red Blue Green

如果让我选择“蓝”并提交表单,我想要的网址是:

http://customsearch.com/result/?Blue

谢谢你任何帮助

回答

0

您可以(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']); 
+0

谢谢安德鲁,我似乎无法看到Roselan的帖子上面,虽然。我可能最终会做1或3,我有一种感觉,这可能会与htaccess混乱 – rocky