0

i have tried to call variable $hetest but it always return with true however i add false as a parameter when i am calling the function

 //function which i call in javascript file
         create_new_user_send_sms(user_Mobile_Number,false)
                              .fail(error => console.error(error))
                              .done(response => {})
   //the ajax call of the function i created 
      function create_new_user_send_sms(mobile_number,hestatus){
            return jQuery.ajax({
              type : "POST",     
              url: ajax_object.ajax_url,
              data: {    
                action : 'create_user_send_sms',     
                mobile_number : mobile_number,
                auto_Login_status : "true",
                he : hestatus,
              },

              success: function (data) {  
              },

              error : function(error){
                  console.log("error:" + error);
              }
           });
        }

//the code in the php function create_user_send_sms
 $mobile_number = $_POST['mobile_number'];
  $auto_Login_status = $_POST['auto_Login_status'];
  $hetest = $_POST['he']; 
  $password = wp_generate_password( 4, false, false );
  • 1
    Does this answer your question? [boolean variables posted through AJAX being treated as strings in server side](https://stackoverflow.com/questions/3654454/boolean-variables-posted-through-ajax-being-treated-as-strings-in-server-side) – Anurag Srivastava Mar 10 '20 at 18:14

1 Answers1

1

Try using the filter_validation function to treat boolean post vars:

$hetest = filter_var ($_POST['he'], FILTER_VALIDATE_BOOLEAN);

Cássio Lacerda
  • 1,554
  • 1
  • 12
  • 14