我想知道是否可以将表单链接中的每个单选按钮链接到不同的动作php页面?如果我有2个单选按钮,一个名为'篮球'还有一个名叫'足球'我可以让他们链接到不同的PHP?这是我的代码;
<form action="football.php" method="post">
<p>Please select your first Sport:</p>
<input type="radio" name="sport" value="football">Football<br></input>
<input type="radio" name="sport" value="basketball">Basketball<br></input>
<input type="radio" name="sport" value="tennis">Tennis</input>
<br><input type="Submit" name="Submit" value="Submit"></form>
答案 0 :(得分:1)
他们有什么理由需要成为不同的页面吗?
<强> form.php的强>
<form action="sport.php" method="post">
<p>Please select your first Sport:</p>
<input type="radio" name="sport" value="football">Football<br></input>
<input type="radio" name="sport" value="basketball">Basketball<br></input>
<input type="radio" name="sport" value="tennis">Tennis</input>
<br><input type="Submit" name="Submit" value="Submit"></form>
<强> sport.php 强>
<?php
if (isset($_POST["sport"])
&& $_POST["sport"] == "football") {
//logic specific for football
} else if (isset($_POST["sport"])
&& $_POST["sport"] == "basketball") {
//logic specific for basketball
} else if (isset($_POST["sport"])
&& $_POST["sport"] == "tennis") {
//logic specific for tennis
} else {
//die or some kind of error handling can be done
}
?>
如果他们绝对需要不同的页面,您可以执行以下操作:
<强> sport.php 强>
<?php
echo "<meta http-equiv='refresh' content='0;url=./dir/subdir/".$_POST["sport"].".php'/>";
//so if posted form data == football, redirect to football.php, etc
?>
当然它缺乏技巧,但除非你使用jQuery / JS,否则你将无法获得理想的结果。