Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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 ?



1.7k
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()



114.3k
Accepted
answer

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

https://docs.phalconphp.com/en/3.0.1/reference/validation.html#cancelling-validations

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

  object(Phalcon\Mvc\Model\Message)[302]
  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