[英]redirect multiple submit button to different page
我在 html 中制作了一個帖子表單,但是我有多個選擇,所以一旦用戶點擊其中一個選擇,它就會將它們重定向到頁面,每個選擇都有不同的選擇,你們能建議我如何實現嗎? 我用 PHP 編碼。
echo "<form action='home.php' method='post'>";
echo "<input type='submit' name='submit' value='Yes'>";
echo "<input type='submit' name='submit' value='No'>";
// If no i want this button to redirect to another page instead of home.php
echo "</form>";
我很感激任何幫助。 我知道這是非常基本的T_T
首先更改提交字段的名稱。 在您的情況下,兩者都是相同的。 我給它是和否。
echo "<input type='submit' name='yes' value='Yes'>";
echo "<input type='submit' name='no' value='No'>";
您可以使用php 中的標頭函數重定向到頁面。 為此檢查提交了哪個按鈕。 如果您單擊是/否,則重定向到您想要的頁面。 你可以通過
if (isset($_POST['yes'])) {
header("Location: home.php") // redirect to your desired page
}
if (isset($_POST['no'])) {
header("Location: anotherPage.php") // redirect to your desired page
}
您可以在提交按鈕中使用formaction
屬性:
<form method="post">
<input type="submit" name="submit" formaction="home.php" value="No">
<input type="submit" name="submit" formaction="otherPage.php" value="Yes">
</form>
這會將表單連同表單中的任何其他參數(如果有)一起提交到所需頁面。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.