How shoul I validate form input

Hi

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



84.5k

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

http://docs.phalconphp.com/en/latest/reference/odm.html#validating-data-integrity http://docs.phalconphp.com/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:

https://github.com/phalcon/cphalcon/blob/1.0.0/unit-tests/ValidationTest.php

Hi

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



84.5k

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

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



10.8k

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 :)