The issue is that if you use text inputs in your form they will always be set, and isset()
will return true
. They are set but may be empty in which case empty()
would make sense, however it returns true
for 0
. is_null()
doesn't make sense here at at all.
if(!is_numeric($_POST['something'])) {
echo "Must be a number";
}
If you construct the inputs as an array like: <input name="numbers[first]" ...>
then you can filter it easily:
$numbers = array_filter($_POST['numbers'], 'is_numeric');
if(!isset($numbers['first'])) {
echo "Must be a number";
}
You can also check into filter_var() for more possibilities.