根据 SELECTvalue POST 到不同的页面?
我有一个表单,具体取决于我想要发送到不同页面的
我不知道执行此操作的最佳方法,但我认为最好的方法可能是有一个中间页面始终发布到,然后让中间页面检查从
谢谢!!
I have a form, depending on the selected value of my <select>
box I would like to send to a different page.
I do not know the best way to do this, but I am thinking that maybe the best way is to have an intermediate page to always post to, then have the intermediate page check the value sent from the <select>
box and forward the POST values to a different page depending on what it is. If this is the best way, how can I do that? If not, what is the best way?
Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一个好办法。另一种方法是使用 Javascript 拦截点击,重写表单的
action
属性并submit()
它。对于您的 PHP:
首页:
第二页:
THat's a good way. The alternative is to use Javascript to intercept the click, rewrite the
action
property of the form andsubmit()
it.For your PHP though:
First page:
Second page:
这当然是用户兼容性的最佳方法。
您可以使用 HTTP 重定向标头来完成此操作,例如,
应在页面有任何输出之前调用该标头。
这样,当用户按下前进/后退按钮时,他甚至不会登陆到中间页面。
我看到的唯一其他选择是使用 javascript 来更改表单目标或这些行中的某些内容,但这有一些警告(必须启用 javascript,代码更复杂,重定向不应该真正发生在页面视图中)
that certainly would be the best method for user compatibility.
you could do it using the HTTP redirect header, e.g.
which should be called before there is any output to the page.
That way the user won't even land on the intermediate page when he presses the forward/back buttons.
the only other option I see would be to use javascript to change the form target or something salong those lines, but that has some caveats (javascript has to be enabled, more complicated code, redirection shouldn't really happen in the view of a page)
然后
,要么将此函数分配给具有“onSubmit”属性的表单,要么使用一个调用该函数的按钮(而不是提交按钮)并在函数末尾添加 document.myform.submit() 。
javascript
Then either assign this function to the form with the "onSubmit" attribute, or have a button (rather than submit button) that calls that function and add document.myform.submit() at the end of the function.
我会使用 javascript 来更改表单的目标,
如果您确实想使用 php,您应该尝试 curl :
i'd use javascript to change the target of the form
if you really want to use php, you should try curl: