Welcome Guest, Not a member yet? Register   Sign In
External functions in form_validation.php file

(This post was last modified: 05-01-2017, 05:49 AM by annx10.)


I want use form_validation.php file with my rules that I put in application/config.

My problem is that some rules need use functions that are for example in models.

I have this in my form_validation.php file:

PHP Code:
$config = array(
'field'  => 'usuario',
'label'  => 'Nombre de usuario',
'rules'  => 'trim|required|max_length[12]|is_unique[' db_table('user_table') . '.username]',
'errors' => array(
'is_unique' => 'El nombre de usuario ya está en uso.'

The function "db_table('table_name')" is in the model: examples/examples_model

If I don't use form_validation.php file, I put in my controller:

Then I can use function "db_table()" without problems when I set set_rules:
$this->form_validation->set_rules('usuario', 'Nombre de usuario', 'trim|required|max_length[12]|is_unique[' . db_table('user_table') . '.username]');

My problem is that if I use form_validation.php file instead set all rules in my controller, I can't use function "db_table()" because it's undefined.

How can I use this external function in my form_validation.php file? Is possible?


Messages In This Thread
External functions in form_validation.php file - by annx10 - 05-01-2017, 05:47 AM

Theme © iAndrew 2016 - Forum software by © MyBB