如果检查答案,PHP如何重定向无线电? [重复]
问题描述:
This question already has an answer here:
Hello I'm Pretty New To PHP I'm trying to Make an Script if the user selects an Radio Option It Will Redirect them to an site.
PHP:
if (isset($_POST["badge"]) ) {
if($_POST["badge"]==="Blue"){
header("Location: /form-error.shtm");
}
HTML:
<form action="badge.php" method="post">
<p>
<input class="with-gap" name="group1" type="radio" id="red" />
<label for="red">Red</label>
</p>
<p>
<input class="with-gap" name="group1" type="radio" id="blue" />
<label for="blue">Blue</label>
<div class="col offset-s7 s5">
<button class="btn waves-effect waves-light red darken-1" type="submit">Submit
<i class="mdi-content-send right white-text"></i>
</form>
</div>
此问题已经存在 这里有一个答案: p>
-
”注意:未定义的变量“,”注意:未定义的索引“和”通知:未定义的偏移“使用PHP
28 answers
span>
li>
ul>
div>
你好我是PHP新手我试图创建一个脚本如果用户选择一个无线电选项它会将它们重定向到一个站点。 p>
PHP: p> \ n
if(isset($ _ POST [“badge”])){ if($ _ POST [“badge”] ===“Blue”){ header(“Location:/ form-error.shtm“); } code> pre>
HTML: p>
&lt; form action =” badge.php“method =”post“&gt; &lt; p&gt; &lt; input class =”with -gap“name =”group1“type =”radio“id =”red“/&gt; &lt; label for =”red“&gt; Red&lt; / label&gt; &lt; / p&gt; &lt; p&gt; \ n&lt; input class =“with-gap”name =“group1”type =“radio”id =“blue”/&gt; &lt; label for =“blue”&gt; Blue&lt; / label&gt; &lt; div class =“col offset-s7 s5”&gt; &lt; button class =“btn waves-effect waves-light red darken-1”type =“submit”&gt; Submit &lt; i class =“ mdi-content-send right white-text“&gt;&lt; / i&gt; &lt; / form&gt; code> pre> div>
答
You are missing values for the radio button and then alone you can check whether the value posted is equal to the value or not.
You HTML need to be altered like this
<form action="badge.php" method="post">
<p>
<input class="with-gap" value="Red" name="group1" type="radio" id="red" />
<label for="red">Red</label>
</p>
<p>
<input class="with-gap" value="Blue" name="group1" type="radio" id="blue" />
<label for="blue">Blue</label>
<div class="col offset-s7 s5">
<button class="btn waves-effect waves-light red darken-1" name="save" type="submit">Submit
<i class="mdi-content-send right white-text"></i>
Since i have provided a name for the submit button i can check with that in PHP page.
badge.php
<?php
if(isset($_POST['save']))
{
if (isset($_POST["badge"]) ) {
if($_POST["badge"]=="Blue"){
header("Location: /form-error.shtm");
}
}
}
?>