PHP filter option won't accepts values from ajax call

I don't know what goes wrong with my script. I have a modal box which contains input fields. An ajax function submit these values to a PHP script. In my PHP script I have these two filters for the input values :

$userID= filter_input(INPUT_POST,"userid", FILTER_SANITIZE_INT);
$feedback = filter_input(INPUT_POST,"feedback", FILTER_SANATIZE_STRING);

But for some reason, these variables are null every time my ajax make a call. I changed these fields to this below:

$userID = $_POST['userid'];
$feedback = $_POST['feedback'];

And then it works I don't know what is not working with the above tow filters option

My ajax call just in case:

     function submitFeedback(){
       $.post(
     "../submitFeedback.php/",
     {
         userid: $("[name=changepasswordID]").val(),
         feedback: $("[name=submitfeedback]").val(),
     },
          function(data){
            $(".feedbackstatusdisplay").html(data);
      },
   );
 }; 

Upvotes: 0

Views: 129

Answers (2)

Mehta Harshit
Mehta Harshit

Reputation: 140

Filter inputs works properly in php $userID= filter_input(INPUT_POST,"userid", FILTER_SANITIZE_INT);//Your code need some changes $userID=filter_input(INPUT_POST,"userid",FILTER_SANITIZE_NUMBER_INT); //FILTER_SANITIZE_NUMBER_INT

this will removes illegal characters from input

$feedback = filter_input(INPUT_POST,"feedback", FILTER_SANATIZE_STRING);

$feedback = filter_input(INPUT_POST,"feedback", FILTER_SANITIZE_STRING);

//change it like FILTER_SANITIZE_STRING

Upvotes: 1

Mohd Alomar
Mohd Alomar

Reputation: 980

Your filters constant are wrong, it is FILTER_SANITIZE_NUMBER_INT and you have typo in the second filter it is FILTER_SANITIZE_STRING

see documentation Sanitize filters

Upvotes: 1

Related Questions