[eluser]marcoslavorato[/eluser]
Hello friends.
I have a problem with my custom form validation class. With a simple method to validate the fields i got a error for extends the default class.
Error:
Code:
Fatal error: Cannot redeclare class MY_Form_validation in /Users/Sites/testes/system/application/libraries/My_form_validation.php on line 44
Code (Libraries folder):
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
* MY_Validation Class
*
* Extends Validation library
*
* Adds one validation rule, "unique" and accepts a
* parameter, the name of the tabela and coluna that
* you are checking, specified in the forum tabela.coluna
*/
class MY_Form_Validation extends CI_Form_Validation {
function MY_Form_Validation($config = array()){
parent::CI_Form_Validation($config);
}
function campo_unico ($valor, $campo){
$CI =& get_instance();
list($tabela, $coluna) = split("\.", $campo, 2);
//Seta mensagem de erro
$CI->form_validation->set_message('campo_unico', '%s já está sendo usado. Tente com outro valor.');
//Verifica se é único (ou não)
$query = $CI->db->query("SELECT COUNT(*) as contador FROM $tabela WHERE $coluna = '$valor'");
$row = $query->row();
//Retorna
if ($row->contador == '0'){
return true;
}else{
return false;
}
}
}
?>
Controller:
Code:
$this->load->library('form_validation');
$this->load->library('my_form_validation');