POST input_filter() in PHP

Hello
Today I am going to show the details about the input_filter() function in PHP for POST method. In this case, we have to create 2 files entitled form.php and form_process.php files. So, let’s start the work-

form.php

<?php
echo showIt();
function showIt(){
$r = ”;
$r .= ‘<form method=”POST” action=”inputFilter.php”>’;
$r .= ‘<table>’;
$r .= ‘<tr><td>ID :</td><td><input type=”text” name=”id2″/> (must be between 3 and 10)</td></tr>’;
$r .= ‘<tr><td></td><td><input type=”submit” name=”submit” value=”POST”/></td></tr>’;
$r .= ‘</table>’;
$r .= ‘</form>’;
return $r;
}
?>

Now, I am going to write the code for form_process.php file. The code is below-

<?php
$id = filter_input(INPUT_POST, ‘id’, FILTER_VALIDATE_INT, array(‘options’=>array(‘min_range’=>3, ‘max_range’=>10)));
 
if(is_null($id)){
       echo “The ID arguments is missing”;
}elseif($id === false){
       echo “The ID argument must be an integar between 3 and 10”;
}else{
       echo “ID is valid : $id”;
}
?>

 

Ok, now run the file of form.php and write the code. Hope it’s ok now. Everything is going well. Isn’t it? Sound good.

Thanks for reading. Bye.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s