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

Can i get Validation message(getMessage) when i use validationHasFailed function?

Can i get Validation message when i use validationHasFailed function if not how to get messages when validation of the model fails ...?

i don't want to save the data in model i just want to know whether validation has failed or nor with failed messages.. i can know if validation had failed using validationHasFailed function. how to get meassges in case validation has failed

What phalcon version you are using? You should call validation method yourself - ti will return boolean true or false if validation was failed. If you want just messages then use $model->getMessages()

edited Feb '17

i am using Phalcon 3.0 can i use $model->getMessages() without calling validate function by just $model->validationHasFailed ?

edited Feb '17

just call validation() on model in order to populate messages array. You don't need to save it if you do not want. And after get messages with getMessages()


In Phalcon 3.0 validationHasFailed shouldn't be used anyway, it's old sutff from Phalcon\Mvc\Model\Validator namespace and shouldn't be used just:

$model->validation(); // to check if valid or not
$model->getMessageS() // to get error messages

So $model->validation() return TRUE or FALSE in case of success and failure of model validation right???

Suppose if there are 3 validations and the model is failed in the first validation itself does it stop there or will it continue validating other 2 validations?

edited Feb '17

It will continue if you don't provide "cancelOnFail" => true, option


i am getting getMessage as an object...how can get the only message instead of getting all the object details

  protected '_type' => string 'Uniqueness' (length=10)
  protected '_message' => string 'Username already allotted' (length=25)
  protected '_field' => string 'user_name' (length=9)
  protected '_model' => null
  protected '_code' => int 0