Issue
I'm coding a project with CI and I have a doubt about the form_validation code, my professor tough me one way to put the rules in the form_validation with arrays, like this
$config = array (
'jugador' =>array(
array(
'field' => 'correoJug',
'label' => 'Correo',
'rules' => 'trim|required|htmlspecialchars',
),
array(
'field' => 'nombreJug',
'label' => 'Nombre',
'rules' => 'trim|required|htmlspecialchars',
),
array(
'field' => 'tagJug',
'label' => 'Tag',
'rules' => 'trim|required|htmlspecialchars',
),
array(
'field' => 'apellidosPatJug',
'label' => 'Apellido paterno',
'rules' => 'trim|required|htmlspecialchars',
),
array(
'field' => 'apellidosMatJug',
'label' => 'Apellido materno',
'rules' => 'trim|required|htmlspecialchars',
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|required|htmlspecialchars',
)
)
);
Where 'jugador' is used for one view, my doubt is the next, I want to use the form_validation for another view, do I need to add another arrays at the end for my another view, like this:
array(
'field' => 'apellidosMatJug',
'label' => 'Apellido materno',
'rules' => 'trim|required|htmlspecialchars',
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|required|htmlspecialchars',
)
)
'OG' =>array(
array(
'field' => 'correoOg',
'label' => 'Correo',
'rules' => 'trim|required|htmlspecialchars',
),
array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|required|htmlspecialchars',
)
);
Or do I need to create another variable in the same file OR I just need to create another form_validation file.
I hope you understand what I'm saying and could help me
Solution
You can create multiple validation array in single file.
$config = array(
'first_validation' => array(
'name' => 'trim|required',
'password' => 'trim|required'
),
'second_validation' => array(
'phone' => 'trim|required',
'email' => 'trim|required'
)
)
and in CONTROLLER
if ($this->form_validation->run('first_validation') == TRUE) {
//success
} else {
// error
}
in some another controller
if ($this->form_validation->run('second_validation') == TRUE) {
//success
} else {
//error
}
Answered By - Saud Khan
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.