Phalcon custom validate message is not showing

217 Views Asked by At

I have app/model/user.php

here is the validation in the model

    public function validation() {

       $this->validation->add(new EmailValidate(array(
           'field' => 'email',
           'message' => 'Please enter a valid Email address'
       )));
    }

When I submit the form it display "email is required" instead of "Please enter a valid Email address"

do I miss something?

1

There are 1 best solutions below

0
On

You have a problem with your code. You are trying to add a new validator to $this->validation. Unless you have extended your own Model base class it should be:

public function validation() {

   $this->add(new \Phalcon\Mvc\Model\Validator\Email(array(
       'field' => 'email',
       'message' => 'Please enter a valid Email address'
   )));
}

Because the validator was not added the email is required message comes from the NOT NULL constraint on the table.