Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Setting form validation error messages after a "successful" validation
#2

[eluser]bluematt[/eluser]
I've managed to solve this, at least cosmetically...

My controller now uses a custom $form_validation->set_error() method instead of $form_validation->set_message():

Code:
if ($this->form_validation->run() && $this->types->create($this->input->post('type'))) {
    redirect('admin/types');
} else {
    $this->form_validation->set_error('type[name]', 'Cannot create a type with that %s.');
    $this->view('admin/types_create');
}

And my customised Form_validation class:

Code:
class MY_Form_validation extends CI_Form_validation {

    function __construct($config=array()) {
        parent::__construct($config);
    }

    function set_error($field, $error) {
        // This is checked by $form_validation->error_string()
        $this->_error_array[$field] = sprintf($error, $this->_field_data[$field]['label']);
        // This is checked by $form_validation->error()
        $this->_field_data[$field]['error'] = sprintf($error, $this->_field_data[$field]['label']);
    }

}


Messages In This Thread
[SOLVED] Setting form validation error messages after a "successful" validation - by El Forum - 03-17-2011, 05:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB