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

How to validate a field itself?

so, its ok to validate the form - but how to validate an induvidial item?

edited Dec '15

Not sure if it's what you're asking : after a form has been validated you can access field by field result :

if(!$form->isValid($data, $entity)) {
    $field = 'nameofthefield';
    if($form->hasMessagesFor($field)) {
        var_dump($form->getMessagesFor($field));
    }
}


28.1k

I wanted to see a

<?php
$name = new Text("name");
$name->addValidator(
    new PresenceOf(
        array(
            'message' => 'The name is required'
        )
    )
);
$name->whatMethodShouldITypeHereWhatSendsMeTrueOrFalseItTheInputIsValidOrNot() ?