• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
$this->form_validation->set_data($this->Data) not working

Good night here staff Brazil,

I'm trying to validate an e-mail and password field, that future will come from the global $ _POST, but I'm porenquanto testing the class I am creating.

Even I already sending a completed array with the data to validate, validation returns me errors that do not exist.

Follows the code of my MODEL (m_login.php):

PHP Code:

('BASEPATH') OR exit('No direct script access allowed');

 * @category Model
 * @tutorial Model responsável por CRIAR, EDITAR, EXCLUIR e LISTAR os USUÁRIOS
 * dentro do PAINEL ADMIN do sistema.
class M_login extends CI_Model {

   private $Level;
   private $Data;
   private $Error;
   private $Result;
   private $Table "ws_users";

   public function ExeLogin($data) {


   public function getUser() {

       $where = array("user_email" => $this->getData()['user_email'], "user_password" => $this->getData()['user_password']);

       $getUser $this->db->get($this->Table)->result_array()[0];

       return $getUser;

   function getData() {


   function getError() {


   function getResult() {


   private function setData($data) {

       $getData array_map("strip_tags"$data);
       $this->Data array_map("trim"$getData);

   private function validateData() {


       $this->form_validation->set_rules("user_email ""Email ""trim|required|valid_email");
       $this->form_validation->set_rules("user_password ""Senha ""trim|required|min_length[6]|max_length[10]");

       if ($this->form_validation->run()):
           $this->Error "Campos validados com sucesso!";
           $this->Result true;
           $this->Error $this->form_validation->error_array();
           $this->Result false;

       return $this->Result;



Follows the code of my CONTROLLER (login.php):

PHP Code:
 * Controller responsável por decidir as ações a serem tomadas
 * para com relação ao login dos usuários dentro do PAINEL ADMIN
class login extends CI_Controller {

   public function index() {

       //Chama as views e passa como parâmetro os dados para serem listados:

       $data["user_email"] = "dcdouglas64@gmail.com";
       $data["user_password"] = "123456";




This is what my CONTROLLER (login.php) is displaying on the screen, I realize that even through e-mail and password validation says the fields are empty (the screen print is attached to this post).

Attached Files Thumbnail(s)

Goodnight everyone, when I try to validate some fields that are NOT within $ _POST, I use the method $this->form_validation_>set_data($data);
But even with my filled field, when I validate a field "required" validation library says the fields are empty.

After much headbanging, I found a validation library (Validation.php), github, which solved my problem.

Follow the link :https://github.com/lumoz/codeigniter-form-validation.

PS: This could be noted to be corrected in future updates.

Interested in what you said, I did a quick test using this

PHP Code:
$data = array(
   'test' => 'This is a test',

$this->form_validation->set_rules('test''Test Field''required|max_length[20]');
if (
   $message "passed validation";
   $message validation_errors();

// Output: 'passed validation' 

So am not sure why your validation is not working, as it seems to be working fine. Other tests with valid_email etc. all behaved as expected.

PS Thought I should mention this is with CI 3.1.0

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.