[eluser]nZac[/eluser]
This is the current code:
Code:
class Somecontroller extends MY_Controller
{
$this->form_validation->set_rules(
array(
array(
'field' => 'cid',
'label' => 'CID',
'rules' => 'required|min_length[6]|max_length[9]|integer|callback_cid_check'
),
array(
'field' => 'e1',
'label' => 'Email',
'rules' => 'required|max_length[60]|valid_email|callback_email_check'
)
)
/**
* visitor_check
*
* @access public
* @param mixed $visitor
* @return bool
*/
function visitor_check($visitor)
{
# Make sure that the function is not just being called by itself
if($this->uri->segment(2) != 'register')
{ $this->template->load('short' , 'public/register'); return TRUE; }
# If visitor is NULL we will use ZMP
if($visitor == NULL )
{ return TRUE; }
else
{
# Make sure they actually put something in here
if($this->input->post('visitor_artcc') == '')
{
$this->form_validation->set_message('visitor_check', 'The Current ARTCC field can not be empty if you are a visitor.');
return FALSE;
}
}
return TRUE;
}
/**
* visitor_check
*
* @access public
* @param mixed $visitor
* @return bool
*/
function dropdown_check($value)
{
# Make sure that the function is not just being called by itself
if($this->uri->segment(2) != 'register')
{ $this->template->load('short' , 'public/register'); return TRUE; }
# Throw the error if the value is false
if(strtoupper($value) == "FALSE")
{
$this->form_validation->set_message('dropdown_check', 'The %s field is required.');
return FALSE;
}
else
{ return TRUE; }
}
/**
* email_check
*
* @access public
* @param mixed $value
* @return bool
*/
function email_check($value)
{
if($this->auth->check_email($value))
{ $this->form_validation->set_message('email_check', 'That email address has already been registered.'); return FALSE; }
else
{ return TRUE; }
}
/**
* email_check
*
* @access public
* @param mixed $value
* @return bool
*/
function cid_check($value)
{
if($this->auth->check_cid($value))
{ $this->form_validation->set_message('cid_check', 'That cid has already been registered.'); return FALSE; }
else
{ return TRUE; }
}
}
My question is, is there a best practice way to abstract the callback functions out of the controller itself and into something else? Helper maybe? Plugin? I am not quite sure.