Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maximum length form validation

Just going through symblog.co.uk symfony2 tutorial. i'm kind of stuck in validations. At first it kept giving erros but i found this article in which author corrects mistakes which source is tutorial being old. anyway, article tells me to change validator in

src/Blogger/BlogBundle/Entity/Enquiry.php:

from

$metadata->addPropertyConstraint('body', new MaxLength(50));

to:

$metadata->addPropertyConstraint('body', new Length(array('min'=> 50)));

It works, yay! Same way i changed

 $metadata->addPropertyConstraint('subject', new MaxLength(50));

into

$metadata->addPropertyConstraint('subject', new Length(array('max'=>50)));

But this time there is no validation performed. Where is the mistake? How should maximum-length validation looks like?

like image 858
Leo Avatar asked Aug 13 '26 22:08

Leo


1 Answers

According to the docs

use Symfony\Component\Validator\Constraints as Assert; 

…

$metadata->addPropertyConstraint('firstName', new Assert\Length(array(
    'min'        => 2,
    'max'        => 10
)));
like image 190
Akkumulator Avatar answered Aug 16 '26 12:08

Akkumulator



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!