发布HTML表单后重定向 [英] Redirect after posting a HTML form
本文介绍了发布HTML表单后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
发布HTML表单后,是否仍然可以重定向用户?
Is there anyway to redirect the user after posting a HTML form?
我有一个看起来像这样的表格
I have a form which looks like this
<form action="/URL/" method="post">
<input type="radio" name="answer" value="W" />W<br />
<input type="radio" name="answer" value="X" />X<br />
<input type="radio" name="answer" value="Y" />Y<br />
<input type="radio" name="answer" value="Z" />Z<br />
<input type="submit" />
</form>
在用户单击提交"按钮后,是否仍可以将用户重定向到新页面?我发现了一些javascript,但是似乎阻止了该帖子的工作:S
Is there anyway I can redirect the user to a new page after they click the submit button? I found a bit of javascript however that seemed to stop the post from working :S
干杯!
推荐答案
如果您使用的是PHP,请在服务器上执行此操作:
If you're using PHP, do it on the server:
if( isset( $_POST['answer'])) {
header( 'Location: http://www.example.com/newurl');
exit();
}
请注意,您应该在header()
调用中使用完整的URL,并且在这种情况下,您可能希望在调用header()
之后使用exit()
.
Note that you should be using a full URL in the header()
call, and that you likely want to exit()
after calling header()
in this case.
这篇关于发布HTML表单后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文