Jezek Jezek Sat Feb 19 18:16:35 -0500 2011

Subject: Fill in form errors automatically.

So I am trying to fill in form errors automatically when an action to create or update a model is called. I try those code though and it gives me a memory size exhausted error.

static $after_validation = array('after_validation');
public function after_validation() {
die($this->is_valid());
}


Devi Mandiri Sat Feb 19 20:07:59 -0500 2011

Try the simple way:

$user = SomeModel::create(array(data));
if ($user->is_invalid())
{
    $error_messages = $user->errors->full_messages();
    print_r($error_messages);
}

Jezek Jezek Sun Feb 20 00:23:57 -0500 2011

Thanks! This is good except the array doesnt list what columns inflicted what errors.

Devi Mandiri Sun Feb 20 00:28:37 -0500 2011
$error_messages = $user->errors->to_array();
print_r($error_messages);
Jezek Jezek Sun Feb 20 04:41:31 -0500 2011

Awesome. It looks like each field has to have a column in the database if I want to run a validation rule against it though?

(1-4/4)