Ver Mensaje Individual
  #6 (permalink)  
Antiguo 02/07/2014, 16:00
Avatar de pateketrueke
pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años, 1 mes
Puntos: 2534
Respuesta: CodeIgniter - Callback_

¿De verdad leíste el manual?

Porque vamos, la función callback debe ser un método de tu controlador y no una función global.

Código PHP:
Ver original
  1. <?php
  2.  
  3. class Form extends CI_Controller {
  4.  
  5.     public function index()
  6.     {
  7.         $this->load->helper(array('form', 'url'));
  8.  
  9.         $this->load->library('form_validation');
  10.  
  11.         $this->form_validation->set_rules('username', 'Username', 'callback_username_check');
  12.         $this->form_validation->set_rules('password', 'Password', 'required');
  13.         $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
  14.         $this->form_validation->set_rules('email', 'Email', 'required|is_unique[users.email]');
  15.  
  16.         if ($this->form_validation->run() == FALSE)
  17.         {
  18.             $this->load->view('myform');
  19.         }
  20.         else
  21.         {
  22.             $this->load->view('formsuccess');
  23.         }
  24.     }
  25.  
  26.     public function username_check($str)
  27.     {
  28.         if ($str == 'test')
  29.         {
  30.             $this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
  31.             return FALSE;
  32.         }
  33.         else
  34.         {
  35.             return TRUE;
  36.         }
  37.     }
  38.  
  39. }
  40. ?>

Y eso se lee perfectamente en el manual, por eso pregunto, ¿qué cosa entendiste?
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.