ZF2 Annotation Validators NotEmpty and Int not working?

Chr Testo

I'm building a form in ZF2 from an entity and everything seems to work fine, except 2 of my validators are ignored for some reason. The Entity looks like this:

  /**
   * @var string $name
   *
   * @ORM\Column(name="name", type="string", length=255, nullable=true)
   * @Annotation\Attributes({"type":"text"})
   * @Annotation\Validator({"name":"NotEmpty"}) // duplicate
   * @Annotation\Options({"label":"Name:"})

   */
  private $name;

  /**
   * @var integer $sort
   *
   * @ORM\Column(name="sort", type="integer")
   * @Annotation\Attributes({"type":"text"})
   * @Annotation\Validator({"name":"Int"}) 
   * @Annotation\Validator({"name":"NotEmpty"})
   * @Annotation\Options({"label":"Sort:"})

   */
  private $sort;  

Yet I can submit the form without any values. I can enter a string in the SORT input, I can leave both fields empty. Why is this not working, why is there no errormessage when I leave the fields empty?

Chr Testo

okay, it's partially because I'm STUPID.

Problem 1: notempty not working is because I defined nullable as true. Seems to override the "notempty" validator. duh.

Problem 2: I still don't know WHY that works, but if I declare the column type as string (instead of integer), suddenly the int validation works.

So here's the right code:

  /**
   * @var string $name
   *
   * @ORM\Column(name="name", type="string", length=255)
   * @Annotation\Attributes({"type":"text"})
   * @Annotation\Validator({"name":"NotEmpty"}) 
   * @Annotation\Options({"label":"Name:"})

   */
  private $name;

  /** 
   * @var integer $sort
   *
   * @ORM\Column(name="sort", type="string")
   * @Annotation\Attributes({"type":"text"})
   * @Annotation\Validator({"name":"Int"}) 
   * @Annotation\Validator({"name":"NotEmpty"})
   * @Annotation\Options({"label":"Sort:"})

   */
  private $sort;   

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

@NotEmpty annotation validator for oneToMany

From Dev

ZF2 deleteAction not working

From Dev

Translation is not working with ZF2

From Dev

ZF2 setCookie not working

From Dev

How to always show single validation message in ZF2 validators?

From Dev

ZF2 form filters and validators. In which cases validators execute first?

From Dev

ZF2 form filters and validators. In which cases validators execute first?

From Dev

ZF2 translator is not working in controller?

From Dev

ZF2 transalation is not working in form class

From Dev

working with session on zf2 (recover container)

From Dev

ZF2 segment child route not working

From Dev

ZF2 route with prefix in not working for default

From Dev

ZF2 : Filedset validation is not working

From Dev

Doctrine with ZF2 Annotation: how to clear a multi select field?

From Dev

How do I use ZF2 regex validators within the factory pattern

From Dev

CausesValidation not working with custom validators

From Dev

CustomValidator not working with other validators

From Dev

CustomValidator not working with other validators

From Dev

Django Custom Validators Not Working

From Dev

ZF2 redirect() not working while header location does

From Dev

ZF2 form HTML5 Number element is not working

From Dev

Hibernate validator validate field with @Length annotation and without @NotEmpty annotation

From Dev

import javax.validation.constraints.NotEmpty; not working

From Dev

import javax.validation.constraints.NotEmpty; not working

From Dev

The Validators And Errors Are Not Working In Angular 9

From Dev

Doctrine2 with MS Server pagination and order by not working under ZF2

From Dev

Angular 2 Multiple validators

From Dev

Zend 2 Form Validators

From Dev

ZF2, I18n and dynamic locale not working anymore after update

Related Related

  1. 1

    @NotEmpty annotation validator for oneToMany

  2. 2

    ZF2 deleteAction not working

  3. 3

    Translation is not working with ZF2

  4. 4

    ZF2 setCookie not working

  5. 5

    How to always show single validation message in ZF2 validators?

  6. 6

    ZF2 form filters and validators. In which cases validators execute first?

  7. 7

    ZF2 form filters and validators. In which cases validators execute first?

  8. 8

    ZF2 translator is not working in controller?

  9. 9

    ZF2 transalation is not working in form class

  10. 10

    working with session on zf2 (recover container)

  11. 11

    ZF2 segment child route not working

  12. 12

    ZF2 route with prefix in not working for default

  13. 13

    ZF2 : Filedset validation is not working

  14. 14

    Doctrine with ZF2 Annotation: how to clear a multi select field?

  15. 15

    How do I use ZF2 regex validators within the factory pattern

  16. 16

    CausesValidation not working with custom validators

  17. 17

    CustomValidator not working with other validators

  18. 18

    CustomValidator not working with other validators

  19. 19

    Django Custom Validators Not Working

  20. 20

    ZF2 redirect() not working while header location does

  21. 21

    ZF2 form HTML5 Number element is not working

  22. 22

    Hibernate validator validate field with @Length annotation and without @NotEmpty annotation

  23. 23

    import javax.validation.constraints.NotEmpty; not working

  24. 24

    import javax.validation.constraints.NotEmpty; not working

  25. 25

    The Validators And Errors Are Not Working In Angular 9

  26. 26

    Doctrine2 with MS Server pagination and order by not working under ZF2

  27. 27

    Angular 2 Multiple validators

  28. 28

    Zend 2 Form Validators

  29. 29

    ZF2, I18n and dynamic locale not working anymore after update

HotTag

Archive