Welcome Guest, Not a member yet? Register   Sign In
Setting rules in a config file not working (bug?)
#1

[eluser]asumaran[/eluser]
I'm trying to validate my form putting the form validation rules in a file form_validation in /myapp/config/

my form_validation.php file looks like this:

Code:
$config = array(
'entrada/publicar' => array(
array(
'field' => 'section',
'label' => 'Sección',
'rules' => 'required'
),
array(
'field' => 'title',
'label' => 'Título',
'rules' => 'required'
),
array(
'field' => 'post_content',
'label' => 'Contenido',
'rules' => 'required'
),
array(
'field' => 'resume',
'label' => 'Resumen',
'rules' => 'required'
),
array(
'field' => 'format',
'label' => 'Formato',
'rules' => 'required|numeric'
),
array(
'field' => 'category',
'label' => 'Categoría',
'rules' => 'required|numeric'
),
array(
'field' => 'target',
'label' => 'Dirigido',
'rules' => 'required|numeric'
),
array(
'field' => 'date',
'label' => 'Fecha',
'rules' => 'required|callback_is_valid_date'
)
)                    
);

my controller (myapp/controllers/entrada.php )
Code:
function publicar()
{
if ($this->form_validation->run() == FALSE)
{
...code
}
else
{
...code
}
}

whith this way nothin happens (or always is valid, the error messages is not displayed), otherwise if I set inline rules en my code, then works


my controller file with rules:

Code:
function publicar()
{
$this->form_validation->set_error_delimiters('<span class="inline_error">', '</span>');
$this->form_validation->set_rules('title', 'T&iacute;tulo', 'required');
$this->form_validation->set_rules('post_content', 'Contenido', 'required');
$this->form_validation->set_rules('resume', 'Resumen', 'required');
$this->form_validation->set_rules('format', 'Formato', 'required|numeric');
$this->form_validation->set_rules('category', 'Categor&iacute;a', 'required|numeric');
$this->form_validation->set_rules('target', 'Dirigido', 'required|numeric');
$this->form_validation->set_rules('date', 'Fecha', 'required|callback_is_valid_date');

if ($this->form_validation->run() == FALSE)
{
//works if form is invalid
}
else
{
//works if worm is valid
}
}

I'm not using routes, _remap,etc.
please, help!
is a bug?

please, sorry for my english :/
#2

[eluser]BrianDHall[/eluser]
I don't use the form validation class anymore really, but to wit:

$config = array(
‘/entrada/publicar’ => array(

...should be:

$config = array(
’entrada/publicar’ => array(

And make sure your controller/function names follow the requirements of the class: http://ellislab.com/codeigniter/user-gui...ngtoconfig
#3

[eluser]asumaran[/eluser]
I've doing something wrong.

I thought I should add 'form_validation' in $autoload['config'] = array('form_validation');

when I removed it, it works!




Theme © iAndrew 2016 - Forum software by © MyBB