Category : assert

I don’t know how to validate a checkbox with a @Assert. Returns a string "1" if checked otherwise false Step 1: create a class: SearchPlayerData.php to test my data (without ORM) This form is not linked to a class <?php namespace AppEntity; use SymfonyComponentValidatorConstraints as Assert; class SearchPlayerData { /** * (length=255, nullable=true) * @Assert??? ..

Read more

I have an entity with @Assert on 2 variables : /** * @ORMColumn(type="date") * @AssertGreaterThan("today", message ="La dade de début ne devrait pas être antérieure à la date du jour ", class="alert") */ private $dateStart; /** * @ORMColumn(type="date") * @AssertExpression( * "this.getDateStart() < this.getDateEnd()", * message="La date de fin ne doit pas être antérieure à ..

Read more

I’m working with Symfony5 and ApiPlatform with phpunit for the tests I’m running tests on field validation. My issue comes from the fact that I want to restrain the user’s possiblity to enter a blank string in a property named name as follow : /** * @ApiResource( * attributes={ * "normalization_context"={"groups"={"cons:read", "cons:list"}}, * "denormalization_context"={"groups"={"cons:write"}} * ..

Read more

On my form, I am using novalidate attribute like this : {{ form_start(form, {‘attr’: {novalidate: ‘novalidate’}}) }} To disable HTML5 browser validation. So Symfony assert errors appears. On the new.html.twig page it works perfectly fine! The novalidate attribute disable the html5 validation and the assert errors appear. But when I use the novalidate attribute on ..

Read more

In Symfony 5.1 project I have a form that indents to partially update User entity records (some fields except of the password and email). The form is generated with a FormBuilder class – a sub-class that extends UserType class, with "password" removed from the builder: class UserProfileSubType extends UserType { public function buildForm(FormBuilderInterface $builder, array ..

Read more

I’m using entity @Assert annotations with different groups tags. /** * @var string * @AssertNotBlank(groups={“basic”}) * @ORMColumn(name=”name”, type=”string”, length=255, nullable=true) */ private $name = null; /** * @var string * @AssertNotBlank(groups={“advanced”}) * @ORMColumn(name=”full_name”, type=”string”, length=255, nullable=true) */ private $fullName = null; So it has basic and advanced groups defined. When I creating the form, I ..

Read more

I have an entity User, which has $password with @AssertLength(min=6) /** * @var string The hashed password * @ORMColumn(type=”string”) * @AssertLength( min=6, minMessage=”Password is too short (min 6 symbols)” ) */ private $password; I’m trying to generate a Login form using createFormBuilder $LoginForm=$this->createFormBuilder(null,[‘data_class’=>User::class]) ->add(’email’) ->add(‘password’, ??? PasswordType::class ??? ) ->getForm(); If I don’t set the ..

Read more

I am trying to pass validation with a the param that can be empty, null, or numeric. When I try to pass empty filed it returns an error : Please check your request and when I leave just @AssertType it passes. /** * @AssertType(type=”numeric”, message=”Tier can be numeric”, groups={“type”}) * @AssertBlank(message=”Tier can be empty string ..

Read more