Welcome Guest, Not a member yet? Register   Sign In
Json and validation rules
#1

[eluser]rurkss[/eluser]
Hello, i am using json to get information like this
Code:
function sendData(baseUrl)
{
  var e = $("#usermail").val();
  var p = $("#phone").val();


$.post(baseUrl+"index.php/main/checkdata_ajax", { "usermail":e, "phone":p },
   function(data){
     if(data.status=="ERR")
      $("#message").html("There are mistakes!");
      else
      $("#message").html("Your data was saved!");
   }, "json");

}

in my controller i can get datas like this
Code:
$phone=$this->input->post('phone');
$usermail=$this->input->post('usermail');
but i want use validation rules, and i'd like to validate that like this
Code:
function checkdata_ajax()
    {
      $this->load->library('validation');
      $rules['usermail']="trim|required|valid_email|xss_clean";  
      $rules['phone']="trim|required|exact_length[13]|numeric";
      $this->validation->set_rules($rules);
      
      if($this->validation->run()==true)
      {
      $res['status']="OK";
      
     //insert to database
          
     $this->db->insert('email_',$data);
      }
      else
      {
        $res['status']="ERR";  
      }
         echo json_encode($res);
    }

in this way it doesn't work at all, can anyone help with that?
#2

[eluser]n0xie[/eluser]
What does:
Code:
console.log(data)
give you?
#3

[eluser]rurkss[/eluser]
i am sory, where should i put that string, in controller?
#4

[eluser]n0xie[/eluser]
In firebug




Theme © iAndrew 2016 - Forum software by © MyBB