The solution is
Codeigniter form_validation by default it will checks for the $_POST data only
To validate the GET method values we need to pass this to
$this->form_validation->set_data($this->input->get());
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function __construct(){
parent::__construct(); // :: Represent static method of codeigniter system core
$this->load->library('form_validation');
}
public function index(){
$this->form_validation->set_data($this->input->get()); //To accept Get method based values
$config = array(
array(
'field' => 'username',
'label' => 'Username',
'rules' => 'trim|required'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|required'
)
);
$this->form_validation->set_rules($config);
if($this->form_validation->run() == FALSE){
$msg=array("err_code"=>1, "message"=>"Invalid Username or Password", "status"=>"FAIL");
echo validation_errors();
echo json_encode($msg);
} else {
$this->load->model('auth/Foundation');
if($this->Foundation->validate_user($this->input->get_post('username'), $this->input->get_post('password'))){
$msg=array("err_code"=>0, "message"=>"Login Success", "status"=>"SUCCESS");
echo json_encode($msg);
}else {
$msg=array("err_code"=>2, "message"=>"User account not exists", "status"=>"FAIL");
echo json_encode($msg);
}
}
}
}
Codeigniter form_validation by default it will checks for the $_POST data only
To validate the GET method values we need to pass this to
$this->form_validation->set_data($this->input->get());
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Login extends CI_Controller {
public function __construct(){
parent::__construct(); // :: Represent static method of codeigniter system core
$this->load->library('form_validation');
}
public function index(){
$this->form_validation->set_data($this->input->get()); //To accept Get method based values
$config = array(
array(
'field' => 'username',
'label' => 'Username',
'rules' => 'trim|required'
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|required'
)
);
$this->form_validation->set_rules($config);
if($this->form_validation->run() == FALSE){
$msg=array("err_code"=>1, "message"=>"Invalid Username or Password", "status"=>"FAIL");
echo validation_errors();
echo json_encode($msg);
} else {
$this->load->model('auth/Foundation');
if($this->Foundation->validate_user($this->input->get_post('username'), $this->input->get_post('password'))){
$msg=array("err_code"=>0, "message"=>"Login Success", "status"=>"SUCCESS");
echo json_encode($msg);
}else {
$msg=array("err_code"=>2, "message"=>"User account not exists", "status"=>"FAIL");
echo json_encode($msg);
}
}
}
}
0 comments:
Post a Comment