Issue
How would you check to see if a user selected one radio option over the other using PHP?
I'm a newbie when it comes to PHP and i've been trying to work with a radio button group where if a user selects Yes the form will relay a success message but if a user selects No a user will be redirected to an error page.
Code below:
PHP
//check to see if the child is not enrolled in school
//If the value of enrolled is No
if (isset($_POST["enrolled"]) ) {
//redirects user to an error page.
header("Location: /form-error.shtm");
}
HTML
<div>
<form>
<fieldset>
<legend>
<span>I am currently enrolled in high-school</span>
</legend>
<div>
<span>
<input id="Yes" name="enrolled" type="radio" value="Yes" />
<label>Yes</label>
</span>
<span>
<input id="No" name="enrolled" type="radio" value="No" />
<label>No</label>
</span>
</div>
</fieldset>
</form>
</div>
Solution
The issue is that on the PHP page, you are using a condition to see if $_POST["enrollment"]
is set, but then you're not checking the value of the variable.
You should do this :
if (isset($_POST["enrollment"]) ) {
if($_POST["enrollment"]==="Yes"){
//success message
}
else{
//redirects user to an error page.
header("Location: /form-error.shtm");
}
}
Answered By - Theox
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.