understanding filter_input and its properties

215 views Asked by At

Given the following code below :

if (isset($_POST['validate']) && trim($_POST['email']) != '') {
    //validate POST input
    $validatePOST = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);
    echo '<div style="background-color:yellow;padding:10px;color:#000;font-size:16px;">POST METHOD</div>';
    if ($validatePOST) {
        echo '<div style="background-color:green;padding:10px;color:#fff;font-size:16px;">
            <b>' . $_POST['email'] . '</b> is a valid email address
          </div>';
    } else {
        echo '<div style="background-color:red;padding:10px;color:#fff;font-size:16px;">
            <b>' . $_POST['email'] . '</b> is  not a valid email address
          </div>';
    }
}

Now, if I was teaching PHP in an english class, is my interpretation as follows right?

$validatePOST = filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);

When you say filter_input(INPUT_POST , 'email') basically what I am saying is:

Hey filter_input can you go check $_POST['email']

And when I add the following filter (in this case FILTER_VALIDATE_EMAIL):

I.e. filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL);

I am basically saying:

Hey filter_input can you go check $_POST['email'] if it's actually an email or something else?

0

There are 0 answers