0

我想知道是否可以将表单中的每个单选按钮链接到不同的操作 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>
4

1 回答 1

1

他们有什么理由需要不同的页面吗?

表单.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>

运动.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
    }
?>

如果它们绝对需要是不同的页面,您可以执行以下操作:

运动.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,否则你将无法获得你想要的结果。

于 2013-10-20T15:22:51.983 回答