Welcome Guest, Not a member yet? Register   Sign In
Multi-field validation callbacks, the "login" form problem, etc.
#16

[eluser]marmida[/eluser]
[quote author="walesmd" date="1195109795"]I think these are pretty unique circumstances that all have a workaround (in this case). Nonetheless, if someone can find a graceful and easy to use solution - I'm sure it would be a welcome addition to the codebase.[/quote]

This is neither as graceful nor as easy to use as I'd like, but here's the patch I hacked in: http://marmida.com/ci/ci_validation_glob...back.patch

I loaded this by putting my modified Validation.php into the app's libraries/ dir, you don't have to actually overwrite the original one.

From the controller's point of view:

Code:
$this->validation->set_fields(array(
    'login' => 'E-mail',
    'password' => 'Password'));
$this->validation->set_rules(array(
    'login' => 'trim|required|valid_email|strtolower',
    'password' => 'trim|required|min_length[4]'));
$this->validation->set_global_rule_callback('_isvalidlogin');

It'd be a lot nicer if this was had the interface of regular rules (e.g. $this->set_global_rules('rule_a|rule_b|callback__rule_c')) but there are some considerations with field name replacements to consider in the error messages that I don't have time to consider right now. Callbacks avoided this, since the callback is then responsible for setting the error message manually.


Messages In This Thread
Multi-field validation callbacks, the "login" form problem, etc. - by El Forum - 11-14-2007, 08:28 PM



Theme © iAndrew 2016 - Forum software by © MyBB