I am trying to use the CALLBACK function inside the filter_input() and get this error:
Warning: filter_input(): First argument is expected to be a valid callback in C:\xampp\htdocs\TEST.php on line ...
Attempt
<form method="POST" name="textfield" id="textfield" action="" required>
<label for="name">Name:</label><br>
<input type="text" name="name" id="name" maxlength="255" size="25">
<br>
<button type="reset">Reset!</button>
<br>
<button type="submit" name="submit" id="submit">Submit!</button><br>
</form>
<?php
if($_SERVER['REQUEST_METHOD']==='POST')
{
$name = $_POST['name'];
function FILTER_VALIDATE_STRING($data)
{
if(is_string($data))
{
$value = TRUE;
}
else
{
$value = FALSE;
}
GLOBAL $value;
return $value;
}
echo FILTER_VALIDATE_STRING($name);
if(!filter_input(INPUT_POST,"name",FILTER_CALLBACK,
"FILTER_VALIDATE_STRING"))
{
die("Enter a valid STRING!");
}
}
?>
I am trying to create a custom VALIDATOR in the function filter_input(). So far, we got these built-into php: A.
filter_input(INPUT_POST,"input",FILTER_VALIDATE_URL)
B.
filter_input(INPUT_POST,"input",FILTER_VALIDATE_EMAIL)
The above 2 VALIDATORS exist. But not this following one:
filter_input(INPUT_POST,"input",FILTER_VALIDATE_STRING)
I am aware that, we have the STRING SANITIZER:
filter_input(INPUT_POST,"input",FILTER_SANITIZE_STRING)
But I don't want to sanitize the user's (form inputer's) input. I want to validate it. So now trying to build my own FILTER_VALIDATE_STRING to use inside the filter_input() function. I know there are other ways of validating a string but I want to learn how to build my own function or whatever to use it with the filter_input() function. That's the assignment for now. I would appreciate anyone editing my code as a fix or answer to this question.