Welcome Guest, Not a member yet? Register   Sign In
private callback functions?
#1

[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;
  }
}

}
?>




Theme © iAndrew 2016 - Forum software by © MyBB