[英]How can I put an Html <form> tag inside a PHP function, which would redirect me to another .php file?
I have been searching for hours on the web and I just can't seem to find an answer.我在网上搜索了几个小时,但似乎找不到答案。
What I want to do is put a <form>
tag inside a php function which would redirect me to another x.php file if a certain criteria is met.我想要做的是在一个 php 函数中放置一个
<form>
标签,如果满足某个条件,它会将我重定向到另一个 x.php 文件。
Sounds simple enough:听起来很简单:
function myFunction() {
if ( Some Condition Here ) {
?>
<form action="x.php">
<button>submit</button>
</form>
<?php
}
}
Obviously the "redirect" won't happen until the form is submitted.显然,在提交表单之前不会发生“重定向”。 Redirecting is done in response to an HTTP request not to "having a form".
重定向是为了响应 HTTP 请求而不是“具有表单”。
You don't use form to redirect , you use a header您不使用表单重定向,而是使用标题
function redirect(url){
header("Location: ".url);
die();
}
so now所以现在
if(some_condition){
redirect("anotherFile.php");
}
For redirect use following code:对于重定向使用以下代码:
header('Location: page.php');
exit;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.