We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

How shoul I validate form input


Just started to explore this framework, so this might be a simple question.

But how should I validate input from form? For example a string length or a password strength.

I can see there are some validation classes but cant figure out on how to use them in my application or how to register my own validator rules?

Best Regards // Johannes


As @Phillipp said you can add validations to your models/collections:

https://docs.phalcon.io/en/latest/reference/odm.html#validating-data-integrity https://docs.phalcon.io/en/latest/reference/models.html#validating-data-integrity

Version 1.0.0 also introduces a validation component which is independent of the models, its documentation is not ready yet, you can see how it works in the following unit tests:



Thank you for reply, I now have a working validator in my model like this.

What I still don't understand is how I get the "message" from my view template?

public function validation() { $this->validate(new EmailValidator(array( 'field' => 'email', 'message' => 'Please provide a valid email' ))); return $this->validationHasFailed() != true; }

regards // johannes


In case that validation fails a message is appended to the messages list:

if ($robot->save()==false) {
    foreach ($robot->getMessages() as $message) {
        echo $message;


The sam thing bothered me for some time :)

'Please provide a valid email' message is activatet with javascript file utils.js in public folder.
I believe you started working from invo example :)