[英]redirect multiple submit button to different page
i made a post form in html, but i have multiple choices so once the user clicks one of the choices then it will redirect them to the page each choice have a different choice can you all advice how can i achieve that?我在 html 中制作了一个帖子表单,但是我有多个选择,所以一旦用户点击其中一个选择,它就会将它们重定向到页面,每个选择都有不同的选择,你们能建议我如何实现吗? im coding in PHP.我用 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>";
I appreciate any help.我很感激任何帮助。 I know this is very basic T_T我知道这是非常基本的T_T
First of all change the name of submit fields.首先更改提交字段的名称。 In your case both are same.在您的情况下,两者都是相同的。 I am giving it as yes and no.我给它是和否。
echo "<input type='submit' name='yes' value='Yes'>";
echo "<input type='submit' name='no' value='No'>";
You can redirect to a page by using header functions in php .您可以使用php 中的标头函数重定向到页面。 For this check which button is submitted.为此检查提交了哪个按钮。 If you clicked on yes/no then redirect to your desired page.如果您单击是/否,则重定向到您想要的页面。 You can check it by你可以通过
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
}
You can use formaction
attribute within your submit buttons:您可以在提交按钮中使用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>
This will submit the form to the desired page, together with any other parameters in your form (if any).这会将表单连同表单中的任何其他参数(如果有)一起提交到所需页面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.