CodeIgniter Forums
private callback functions? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: private callback functions? (/thread-46539.html)



private callback functions? - El Forum - 11-04-2011

[eluser]dadamssg[/eluser]
How do you set private callback functions? It seems they must be public to use codeigniter's callback form validation functions. In the example in the user guide(below) a random user could go to "http://www.codeigniter.com/index.php/form/username_check". In this instance the user probably wouldn't see anything but if the function was a little more complicated and certain inputs were expected they could get a bunch of errors.


Code:
<?php

class Form extends CI_Controller {

function index()
{
  $this->load->helper(array('form', 'url'));

  $this->load->library('form_validation');

  $this->form_validation->set_rules('username', 'Username', 'callback_username_check');
  $this->form_validation->set_rules('password', 'Password', 'required');
  $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
  $this->form_validation->set_rules('email', 'Email', 'required');

  if ($this->form_validation->run() == FALSE)
  {
   $this->load->view('myform');
  }
  else
  {
   $this->load->view('formsuccess');
  }
}

function username_check($str)
{
  if ($str == 'test')
  {
   $this->form_validation->set_message('username_check', 'The %s field can not be the word "test"');
   return FALSE;
  }
  else
  {
   return TRUE;
  }
}

}
?>