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

#1
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:
<?php

defined
('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 METHODS
 
   public function ExeLogin($data) {

 
       $this->setData($data);
 
       $this->validateData();
 
   }

 
   public function getUser() {


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

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

 
       return $getUser;
 
   }

 
   function getData() {
 
       return

                $this
->Data;
 
   }

 
   function getError() {
 
       return

                $this
->Error;
 
   }

 
   function getResult() {
 
       return

                $this
->Result;
 
   }

 
   //PRIVATE METHODS
 
   private function setData($data) {

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

 
   private function validateData() {

 
       $this->form_validation->set_data($this->Data);

 
       $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;
 
       else:
 
           $this->Error $this->form_validation->error_array();
 
           $this->Result false;
 
       endif;

 
       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:
 
       $this->load->view("dashboard/includes/v_header");
 
       $this->load->view("dashboard/autenticacao/v_form-login");
 
       $this->load->view("dashboard/includes/v_footer");


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

 
       $this->m_login->ExeLogin($data);
 
       var_dump($this->m_login);
 
   }

}

?>




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)
   
Reply

#2
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.
Reply

#3
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_data($data); 
$this->form_validation->set_rules('test''Test Field''required|max_length[20]');
if (
$this->form_validation->run()) 
{
 
   $message "passed validation";
}
else
{
 
   $message validation_errors();
}
echo 
$message;

// 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
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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