How to validate certain values in PHP if (almost?) are all received from the form as a string?

1

I do not know if they are all values, but in general, PHP gets everything as string when it comes from a form. Let's say I want to validate age:

<form method="POST" action="test.php">
    <input type="text" name="age">
    <button type="submit">Manda</button>
</form>

And in test.php :

if(!is_int($_POST['age'])){
    echo 'não é integer';
    var_dump($_POST['age']);
}

You can see that using var_dump() I get the information from " age " as a string and enter if , even typing 14 on the form, for example. So how do I validate certain values in PHP if (almost?) All are received from the form as string ?

Examples will be welcome.

    
asked by anonymous 01.12.2017 / 14:25

1 answer

0

But what exactly would you like to do? PHP is a bit simplistic in this part. if you get a variable that only has numbers and add to another that only has numbers it will calculate normally as if it were integer for example

if($_POST['age'] >= 18){ echo "pessoa é maior de idade"; } 
    
01.12.2017 / 14:32