Welcome Guest, Not a member yet? Register   Sign In
Issu form_validation
#1

PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class 
Login extends CI_Controller {
  function 
__construct(){
    
parent::__construct();
    
$this->load->helper(array('form','url'));
    
$this->load->model('m_login');
    
$this->load->library('session''form_validation');
  }
  function 
index()
  {
    
$this->load->view('admin/v_login');
  }
  function 
valid(){
    
$data=array(
      
'username'=>$this->input->post('username'),
      
'password'=>$this->input->post('password')
      );
    
$this->form_validation->set_error_delimiters('<div class="error">''</div>');
    
$this->form_validation->set_rules('username''Username''trim|required|xss_clean');
    
$this->form_validation->set_rules('password''Password''trim|required|xss_clean');
    if (
$this->form_validation->run() == FALSE) {
        
$this->m_login->m_aksi($data);
        
$this->session->set_userdata($data);
        
redirect('admin/login/sukses''refresh');
    }else{
      
$this->load->view('admin/v_login');
    }
  }
  function 
sukses()
  {
    
redirect('admin/dasabor''refresh');
  }
  function 
logout(){
    
$this->session->unset_userdata('');
    
$this->load->view('admin/v_login');
  }


Error message :


A PHP Error was encountered

Severity: Notice

Message: Undefined property: Login::$form_validation

Filename: admin/login.php

Line Number: 19

Backtrace:

File: C:\xampp\htdocs\cms\application\controllers\admin\login.php
Line: 19
Function: _error_handler

File: C:\xampp\htdocs\cms\index.php
Line: 292
Function: require_once
Reply
#2

Hello komang,

According to CI3 User Guide, look at Loader Class and you'll see that you can't pass two libraries as two string parameters. The class will try here to load the session class with a form_validation parameter, which is interpreted as a var that doesn't exist at all.

The good way is to chain load :

PHP Code:
$this->load->library('session')
 
          ->library('form_validation'); 

Or even the same array method that you used to load helpers in constructor Tongue
Reply
#3

Or (also in the userguide) use an array...
$this->load->library(array('session', 'form_validation'));
Reply
#4

ok i am try
Tanks all
Reply
#5

How to view specific error in form?
Reply
#6

It would be a good idea to rtfm... http://www.codeigniter.com/docs
Reply
#7

@Avenirer : Agree with you, but it would be great to redirect him to the right page of userguide ^^

@komang: Here are form validation error handling Smile

You should add the UserGuide to your bookmarks !
Reply
#8

Hi Komang,

You can Load session library in autoload.php as well. As you have to use session in maximum pages.
Reply
#9

Help me to use xss_clean in form_validation?
i am trying still an error as below.
Unable to access an error message corresponding to your field name Username.
Unable to access an error message corresponding to your field name Password.

this my code to use xss_clean:
PHP Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class 
Login extends CI_Controller {
 
 function __construct(){
 
   parent::__construct();
 
   $this->load->helper(array('form','url'));
 
   // $this->load->model('m_login');
 
   $this->load->library(array('session''form_validation'));
 
 }
 
 function index()
 
 {
 
   $this->load->view('admin/v_login');
 
 }
 
 function valid(){
 
   $this->form_validation->set_error_delimiters('<div class="merah">''</div>');
 
   $this->form_validation->set_rules('username''Username''required|xss_clean');
 
   $this->form_validation->set_rules('password''Password''required|xss_clean');
 
   if ($this->form_validation->run() == TRUE) {
 
     $data=array(
 
     'username'=>$this->input->post('username'),
 
     'password'=>$this->input->post('password'
 
     );
 
     if ($data['username'] == 'admin' && $data['password'] == '1234') {
 
       $this->session->set_userdata($data);
 
       redirect('admin/login/sukses');
 
     }else{
 
       return TRUE;
 
     }

 
     
    
}else{
 
     $this->load->view('admin/v_login');
 
   }
 
 }
 
 function sukses()
 
 {
 
   redirect('admin/dasabor''refresh');
 
 }
 
 function logout(){
 
   $this->session->sess_destroy();
 
   $this->load->view('admin/v_login');
 
 }


and i set
PHP Code:
$config['global_xss_filtering'] = TRUE
Huh
Reply
#10

(This post was last modified: 03-04-2015, 05:47 PM by CroNiX. Edit Reason: add link to userguide )

You'd also need to show us the view where you are trying to display the error messages. You also don't use xss_clean for a validation rule. More recent versions of CI removed that. See the available rules in the CI3 userguide.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB