[eluser]heat23[/eluser]
I've spent several hours trying to get this working many CI Forum/ Google searches later, here I am... Here is what I did so far, please let me know what I am doing wrong. By the way, I am using PHP 4 and CI 1.7.1
1) I created the file MY_Form_validation.php in the /application/libraries folder
2) Inside this file, I have:
Code:
<?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 {
function MY_Form_validation($config = array())
{
parent::CI_Form_validation($config);
$this->CI =& get_instance();
}
function type_check($str)
{
echo "111111";
if($str==0){
$CI->validation->set_message('trade_type_check','You must select a type');
return false;
}
return true;
}
}
3) In my controler which contains the form, I have:
Code:
$this->load->library(array('form_validation'));
$rules['type'] = "type_check";
$this->form_validation->set_rules($rules);
$fields['type'] = 'Type';
$this->form_validation->set_fields($fields);
if($this->input->post('submit')){
if ($this->form_validation->run() == FALSE) //Fail
{
echo 'Form had errors';
}
else //Success
{
echo 'Form submitted Successfully';
}
}
4) When I submit the form, I get the error
Code:
Fatal error: Call to undefined method: my_form_validation->set_fields() in C:\www\ci\system\application\controllers\c_eval.php on line 74
Which corresponds to the line:
$this->form_validation->set_fields($fields);
Can someone tell me what I am doing wrong here?