Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
[ORM - Observer validation before_save] How to set validation message?
  • Hey, I'm using the observer_validation from the ORM package. I have a custom validation function in my model which works, but I don't know how to get the validation instance to set the validation error message dynamically. I tried something like: (just an example)
    function _validation_password_hash($value) {
    if( $value == "" )
    {
    $val = Validation::instance(); // does not work apparently
    $val->set_message('password_hash', "Passwort darf nicht leer sein");
    return false;
    }
    } But the message is still: "Validation rule password_hash failed for password". Thanks in advance,
    Matthias
  • The Observer_Validation uses an instance named after the Model's class. For validating Model_Example this might look like this:
    $val = Validation::instance('Model_Example');
    $val->set_message('password_hash', 'Passwort darf nicht leer sein');
    

    You can also set validation messages in a lang file named validation.php by the way, which is the much preferred way to the above. There's a small example of such a file in the core.
  • Jelmer Schreuder wrote on Tuesday 6th of September 2011:
    The Observer_Validation uses an instance named after the Model's class. For validating Model_Example this might look like this:
    $val = Validation::instance('Model_Example');
    $val->set_message('password_hash', 'Passwort darf nicht leer sein');
    

    You can also set validation messages in a lang file named validation.php by the way, which is the much preferred way to the above. There's a small example of such a file in the core.

    Thanks very much Jelmer!

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion