Welcome Guest, Not a member yet? Register   Sign In
[SLOVED] Controller Showing Two Callback Validation Messages.
#1

[eluser]riwakawd[/eluser]
When my call back is in effect it shows up two errors on my login form I am only wanting my custom error to show up.

How do I stop the second error message from showing up. Here is a sample image of my errors that are showing up. Error Message Sample Image


Second Error Message: Unable to access an error message corresponding to your field name.

I use hmvc also with my callbacks.

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends Controller {
      
   private $error = array();
      
   public function __construct() {
      parent::__construct();
      $this->load->library('user');
      $this->load->library('form_validation');
      $this->lang->load('common/login', 'english');
      if($this->session->userdata('user_id')) {
         redirect('dashboard');
      } else {
         return false;
         redirect('login');
      }
   }

   public function index() {
      $this->form_validation->set_rules('username', 'Username', 'required|min_length[4]|max_length[12]|xss_clean|callback_validate');
      $this->form_validation->set_rules('password', 'Password', 'required|xss_clean');

      if($this->form_validation->run($this) == false) {
        
         if (array_key_exists('warning', $this->error)) {
            $data['error_warning'] = $this->error['warning'];
         } else {
            $data['error_warning'] = '';
         }

         $data['action'] = site_url('login');

         $this->load->view('common/login.tpl', $data);
      } else {
          redirect('dashboard');
      }
   }

   public function validate() {
      $username = $this->input->post('username');
      $password = $this->input->post('password');

      if ($this->user->login($username, $password)) {
          return true;
      } else {
         $this->error['warning'] = $this->lang->line('error_login');
         return !$this->error;
      }
   }
}
#2

[eluser]CroNiX[/eluser]
You're setting the error message wrong in your validate() method, so it can't find it. See the user guide.
http://ellislab.com/codeigniter/user-gui...tingerrors

You'd need to show your view file to narrow down the first error since that's where it's being displayed. It just doesn't look like you are using the validation library properly.

Also validation rules that manipulate the input value, like xss_clean, should come after all other rules otherwise you can have unpredictable results.
#3

[eluser]riwakawd[/eluser]
[quote author="CroNiX" date="1404061458"]You're setting the error message wrong in your validate() method, so it can't find it. See the user guide.
http://ellislab.com/codeigniter/user-gui...tingerrors

You'd need to show your view file to narrow down the first error since that's where it's being displayed. It just doesn't look like you are using the validation library properly.

Also validation rules that manipulate the input value, like xss_clean, should come after all other rules otherwise you can have unpredictable results.[/quote]

But I know about the set_message but can not seem to get it in my area I would like. As you can see in view I have normal error message. But have my error message at top
#4

[eluser]riwakawd[/eluser]
[quote author="CroNiX" date="1404061458"]You're setting the error message wrong in your validate() method, so it can't find it. See the user guide.
http://ellislab.com/codeigniter/user-gui...tingerrors

You'd need to show your view file to narrow down the first error since that's where it's being displayed. It just doesn't look like you are using the validation library properly.

Also validation rules that manipulate the input value, like xss_clean, should come after all other rules otherwise you can have unpredictable results.[/quote]


I worked it out today. When want to use both validation methods custom and form validation can not use callbacks. So I added check $this->validate() method in else area in form validation.

Code:
public function index() {
      $this->form_validation->set_rules('username', 'Username', 'required|min_length[4]|max_length[12]');
      $this->form_validation->set_rules('password', 'Password', 'required|xss_clean');

      if($this->form_validation->run($this) == false) {

         $data['title'] = $this->lang->line('heading_title');

         $data['text_heading'] = $this->lang->line('text_heading');
        
         if (array_key_exists('warning', $this->error)) {
            $data['error_warning'] = $this->error['warning'];
         } else {
            $data['error_warning'] = '';
         }

         $data['action'] = site_url('login');

         $this->load->view('common/login', $data);

      } else {

         if($this->validate()) {

             redirect('dashboard');

            } else {

               $data['title'] = $this->lang->line('heading_title');

               $data['text_heading'] = $this->lang->line('text_heading');

               if (array_key_exists('warning', $this->error)) {
                  $data['error_warning'] = $this->error['warning'];
               } else {
                  $data['error_warning'] = '';
               }

               $data['action'] = site_url('login');

               $this->load->view('common/login', $data);

         }
      }
   }

function validate() {
      $username = $this->input->post('username');
      $password = $this->input->post('password');

      if ($this->user->login($username, $password)) {
          return true;
      } else {
         $this->error['warning'] = $this->lang->line('error_login');
         return !$this->error;
      }
   }




Theme © iAndrew 2016 - Forum software by © MyBB