Issue
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>
Solution
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");
}
}
}
?>
Answered By - Naresh Kumar P
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.