Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 3 - Extending Form Validation not working
#3

Dear CroNiX,

First i thanks to you for replied my message.

I got another Isssue.

application/libraries/MY_Form_validation.php
=================================

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

//include_once BASEPATH . '/libraries/Form_validation.php';

class MY_Form_validation extends CI_Form_validation {

public function __construct($rules = array())
{
parent::__construct();
$this->CI =& get_instance();
$this->_config_rules = $rules;
}

public function is_required($str)
{
if(empty($str))
{
$this->CI->form_validation->set_message('is_required', 'The %s is required');
return FALSE;
}
else
{
return TRUE;
}
}
}
?>

Controller/User.php
=============
class User extends MY_Controller {

function __construct()
{
parent::__construct();
$this->CI =& get_instance();

}
function login()
{
if($this->input->post('submit'))
{
$this->CI->form_validation->set_rules('username', 'Username', 'is_required');
$this->CI->form_validation->set_rules('password', 'Password', 'is_required');
if ($this->CI->form_validation->run() == FALSE)
{
echo " Failed <br/>";
}
else
{
echo " Success <br/>";
}
}
}
}

core/MY_Controller.php
=====================

class MY_Controller extends CI_Controller {

// html header variables
public $title;
public $keywords;
public $description;

// template specific dynamic variables
public $current_menu;
public $current_sub_menu;
public $doc_heading;
public $breadcrumbs;
public $template_msg;
public $template_err;
public $content;
public $ajax = FALSE;

// js and css specific variables
public $onload_js;
public $internal_css;
public $internal_js;
public $tbname;


function __construct()
{

parent::__construct();

// CodeIgniter libraries and helpers

$this->load->helper(array('security', 'form', 'url', 'date', 'download', 'file', 'language'));

// Userdefined project specific helpers

$this->load->helper(array('ui', 'constants'));

//Load userdefined model

$this->load->model('process'); //process related data

//Load validation library
$this->load->library(array('session', 'upload', 'form_validation', 'pagination', 'email', 'image_lib'));
}
}

=================

Vie file a same as previous message.

Output:
if i am submit form with empty fileds,then i got "SUCCESS".

How can this execute. I think , it does not call MY_Form_validation 's is_required().
Please help me CroNiX.
Reply


Messages In This Thread
RE: CodeIgniter 3 - Extending Form Validation not working - by grsabarish - 09-03-2015, 10:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB