![](/img/trans.png)
[英]How can you put a php function inside of an html form inside of a php echo?
[英]How can I put an Html <form> tag inside a PHP function, which would redirect me to another .php file?
我在網上搜索了幾個小時,但似乎找不到答案。
我想要做的是在一個 php 函數中放置一個<form>
標簽,如果滿足某個條件,它會將我重定向到另一個 x.php 文件。
聽起來很簡單:
function myFunction() {
if ( Some Condition Here ) {
?>
<form action="x.php">
<button>submit</button>
</form>
<?php
}
}
顯然,在提交表單之前不會發生“重定向”。 重定向是為了響應 HTTP 請求而不是“具有表單”。
您不使用表單重定向,而是使用標題
function redirect(url){
header("Location: ".url);
die();
}
所以現在
if(some_condition){
redirect("anotherFile.php");
}
對於重定向使用以下代碼:
header('Location: page.php');
exit;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.