So we get this school task where we need to check if one of the fields is unfilled and display an error. We did this but for some strange reason it doesn’t display a error when a radio button is unchecked (a textfield null check works fine).
I’ve tried with a friend many possibilities but they all don’t seem to work. We have been stuck at this task for two hours. Now we have tried making separate if‘s but that doesn’t seem to work too.
These are the important parts:
<p>
<input type="hidden" name="taal" value="false">
Choose a language
<input type="radio" name="taal" value="N"> Dutch
<input type="radio" name="taal" value="E"> English
<input type="radio" name="taal" value="S"> Spanish
if (@$_POST['taal'] == null){
echo "No Language gotten";
return;
}
You can omit the hidden tag:
And use
isset()to check whether the value was sent. If none of the radio buttons are checked,taalwill simply not be added to the posted data. So you have to check for whether it was set or not, you can do this withisset():Also, in most cases, it is recommended not to use the
@operator. Error messages (warnings, notices, etc.) are there to warn you about a problem in your code. Fix the problem instead of hiding it, or it might come back and bite you later.