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

Problem with PresenceOf validation messages

Hi everyone !

Once again i've a little problem !

I read a lot of interessant topics talking about very similar problem as mine, but it seems that my issue is a little bit different.

In fact i'm trying to use Phalcon\Mvc\Model\Validator\PresenceOf like that

  public function validation()
  {
      $this->validate(new PresenceOf(
          array(
              "field"  => "nameAlbum_en",
              "message" => "Please be sure to fill the album's name !"
          )
      ));
      $this->validate(new Uniqueness(
          array(
              "field"   => "nameAlbum_en",
              "message" => "The album name must be unique !" 
          )
      ));
      return $this->validationHasFailed() != true;
  }

The Uniqueness validator works perfectly i have the message i was excepting, but for the PresenceOf i expected to see my message or at least the default message (like the others which had almost the same problem as me in this forum). But it displays absolutly nothing, i tried to disable the nullValidations with the following code:

  public function initialize() {
    $this->setup(array(
        'notNullValidations'=>false,
    ));
  }

Do you have any idea why the flash message isn't displayed (at least the default message) ?

Thanks for you help and sorry to bother, if the solution already have been given somewhere

Brieuc



2.1k
edited Jan '15

 public function validation()
  {
      $this->validate(new PresenceOf(
          array(
              "field"  => "name", // << -- field?
              "message" => "Please be sure to fill the album's name !"
          )
      ));
      $this->validate(new Uniqueness(
          array(
              "field"   => "name",
              "message" => "The album name must be unique !" 
          )
      ));
      return $this->validationHasFailed() != true;
  }

presenceof will validate true so long the field is set, it doesnt matter if its jibberish or even just a single charc. so long there is something filled its valid.

edited Jan '15

Sorry i made a mistake while copying my code here, but that's already what i have the field's name is exactly the same. (I edited the first post in order to avoid confusing people in future). And what's you´re describing is the behaviour i'm expecting, but i let empty the input and it doesn't display any errors ... i'm pretty confuse on this one ...



7.0k
Accepted
answer
edited Jan '15

Phalcon 1.3.4 is running on my server !

And if i understood well what you tried to tell me, it's exactly the same to do:

return $this->validationHasFailed() != true;

or

if ($this->validationHasFailed() == true) {
    return false;
}

EDIT:

Oh god ! I'm so stupid, i had a conflict with my formsValidator ... So if someone encountered the same problem, check you're formsValidator it may be doing some actions which will change the behaviour ..