We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Cannot get Model Validation working for email field

In Controller i have:

$email = $this->request->getPost('email');

            $obj = new Users();
            $valid = $obj->validation($email);

if(!$valid)
        {
            $this->flashSession->error("invalid email!");
        }
         else
         {
            $this->flashSession->success("good email!");
         }

In Model:

public function validation($email) { $this->validate( new Email( array( 'field' => 'email', 'required' => true, ) ) );

    if ($this->validationHasFailed() == true) {
        return false;
    }
}

Validation always returns error message. Please advise, what i am lacking!

$obj->validation shoud not be called directly, it's automatically called when you call "save" on that object.



14.9k
edited Apr '15

This is Sign In form, so I will not save any data here. I just need to validate the email address and have no clue how to do it correctly using "validation" method.

$obj->validation shoud not be called directly, it's automatically called when you call "save" on that object.



14.9k
edited Apr '15

Yes, you are right, Model Validation and Simple validation are different things and should be treated differently.