Welcome Guest, Not a member yet? Register   Sign In
extended Form Validation/setting custom error messages and errors
#2

[eluser]LAMP Coder[/eluser]
Modified methods: set_rules, error_string

Why?
I wanted to be able to set custom errors by every field on the run instead of using the field name.

Usage:
Quote: $this->form_validation->set_rules('field_name', 'readable name', 'required', 'This field is require, no matter what!!');


Added methods: set_error, custom_errors

Why?

Sometimes, I had to run some validations based on more then one fields.

I.e. in case if "state" was required in case if user selects "United States" or in something else that i couldn't push through the form validation class.. such as.. if i check the login and login comes out to be incorrect. I should be able to set an error message "Invalid username/password" I know it's not a form validation error... but i wanted i wanted form validation to handle displaying errors,
Quote: $this->form_validation->set_error('Yada Yada Yada!!');

if you're using set_error, you'll have to do following:
Code:
if($this->Form_validation->custom_errors() == FALSE && $this->Form_validation->run() == FALSE)
{
      //no errors, let's do something here
}

instead of:
Code:
if($this->Form_validation->run() == FALSE)
{
      //no errors, let's do something here
}


and last but not the least, you can use following to display the errors
Code:
<?php echo validation_errors(); ?>


Messages In This Thread
extended Form Validation/setting custom error messages and errors - by El Forum - 10-22-2009, 02:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB