Welcome Guest, Not a member yet? Register   Sign In
trigger form_error without going through the form_validation->run()
#1

[eluser]Dennis_gull[/eluser]
Is it possible to trigger the the form_error without using $this->form_validation->run()?

For example if a user is signing in I want the regular validation to run then after the validation I want to check the database to see if the information match anyone, if it does I need to take this information and save it in the session, example:

Code:
if( $this->form_validation->run('login_user') )
{
    $result = $this->db->select('id, username, language')->from('users')->where($where)->get()->row();
    if(count($result) == 1)
    {
        // continue with login using the $result variable
    }
    else
    {
        // trigger form error
    }
}

For this example I can't use a custom_validation because I need the user information after the validation and I don't want to run the query twice.
#2

[eluser]OliverHR[/eluser]
I think the anwser is no. You can try to validate your query with a Callback.
#3

[eluser]Dennis_gull[/eluser]
[quote author="OliverHR" date="1265752761"]You can try to validate your query with a Callback.[/quote]

Yeah but then I won't get the query result once its validated.
#4

[eluser]Dennis_gull[/eluser]
I had to create a solution for this so I put the following function in my MY_form_validation.php:

Code:
function set_error($field, $message, $label = '')
{
    $this->_field_data[$field]['error'] = sprintf($this->CI->lang->line($message), $this->_translate_fieldname($label));
}

then you use it like this:
Code:
$this->form_validation->set_error('my_form_field','my_language_field', 'lang:my_label');




Theme © iAndrew 2016 - Forum software by © MyBB