Skip to main content
Filter by
Sorted by
Tagged with
2 votes
2 answers
99 views

Handle Entity classes with Symfony Validator component

I'm trying to use symfony/validator outside of Symfony by just installing composer require symfony/validator (vemphasized text7.1) Following this guide https://symfony.com/doc/current/components/...
Arno van Oordt's user avatar
1 vote
1 answer
122 views

Symfony Validator does not work with nested AtLeastOneOf Constraint

In following code (condensed from a project) the validation for $constraint2 returns no error, which is not the behaviour I expect (should also return errors): use Symfony\Component\Validator\...
MSchmidt's user avatar
0 votes
0 answers
323 views

Catching ValidationFailedException in a listener or subscriber

I'm building a simple REST api with Symfony 7 and using MapRequestPayload attribute to automatically map request data into an object. Validation is also handled automatically with symfony/validator. //...
keune's user avatar
  • 5,795
3 votes
1 answer
3k views

Symfony: how to apply Assert\Valid to each element of an array?

I have a complex data-type given by a class FormatInstance with a couple properties. Some of them with attributes like #[Assert\NotBlank]. I am using this class in an array in one of my entities like ...
Wolfone's user avatar
  • 1,426
2 votes
0 answers
73 views

How can I define an over-arching validation error message for a Symfony Validator Compound / Sequence constraint?

Using the Symfony Validator, I can create a Compound constraint by inheritance: // source: https://symfony.com/doc/current/reference/constraints/Compound.html // src/Validator/Constraints/...
Katai's user avatar
  • 2,927
0 votes
0 answers
108 views

Pass object fields to RepeatedType form field

I have class with user data and i would like to validate it by form. I have issue with password field. Field with password in form: add('password', RepeatedType::class, [ '...
Tomasz Filipek's user avatar
1 vote
1 answer
1k views

symfony/validator: how to validate string as int

I created a contoller in Symfony that will be handle API requests. I want to validate action request. Parameter 'type' of the request must be integer. There is controller action code: public function ...
raskopin's user avatar
0 votes
1 answer
1k views

Symfony Collection Validation

I've building a quick API with Symfony 6.1 and custom validators to validate my inputs, and I'm struggling with the syntax. I made this: $constraint = new Collection([ 'fields' => [ ...
TEOL's user avatar
  • 89
4 votes
1 answer
730 views

API Platform DTO Validator - Missing properties are no violation

I have an API Platform DataTransformer that uses an injected ValidatorInterface to verify the JSON POST body of an incoming request. It is basically a copy of the example in the docs: <?php ...
Cologne_Muc's user avatar
0 votes
1 answer
173 views

FunctionalTest Validator: Comparison with other property

based on the example LessThan.html#propertypath I would like to write a FunctionalTest for my own validator @Assert\Amount. $amount is to be validated depending on $currency. My question is, how can I ...
Bademeister's user avatar
0 votes
1 answer
254 views

Compound validation rules without extending the Compound constraint with Symfony Validator

I'm using the validator component as a standalone package for data validations. I have a class that contains methods that return common validation cases, like this one: public function ...
dakujem's user avatar
  • 179
3 votes
1 answer
1k views

UniqueEntity with two (many) fields is not working

I have a problem related to using Symphony (v5.4) with API Platform based on PHP 8.1. I have an entity called Customer which has email, phoneNumber fields that are unique per tenantId (two fields per ...
Patryk Woziński's user avatar
0 votes
1 answer
1k views

symfony 5.4 validation constraints with groups are ignored

This annotation of a constraint works: use App\Api\Dto\DtoInterface; use Nelmio\ApiDocBundle\Annotation\Model; use OpenApi\Annotations as OA; use Symfony\Component\Serializer\Annotation\Groups as ...
Calamity Jane's user avatar
1 vote
1 answer
1k views

How to get nested error messages with Symfony Validator?

I am trying to validate raw values like described in the Symfony docs. https://symfony.com/doc/current/validation/raw_values.html When I provide the name key in the input - I see nested errors. But ...
Jlblcblu's user avatar
  • 133
-1 votes
1 answer
193 views

Symfony validator conditional validation

* @Assert\Type(type="array") * @Assert\Count( * min=5, * max=10 * ) I need validate a type array and then I need to validate if the array has a min and max count. But when I ...
user2219071's user avatar
1 vote
0 answers
425 views

symfony custom form field not valid

I am using symfony 6 with everything updated to date. I created a form type with which I intend to receive a url or an image and internally transform the image into a url that will indicate where it ...
quetzalfir's user avatar
-1 votes
1 answer
269 views

Symfony Validation on Relations

Suppose I have the following Entities: Pizza PizzaType = [Cheese, Meat, Vegetable, Supreme] Toppings = [Pepperoni, Sausage, Peppers, Mushrooms] When I create a pizza and set its type to Meat I want to ...
snoop168's user avatar
  • 404
2 votes
1 answer
826 views

Sequently validate two different constraints with Symfony

I'm using Symfony 4.4 and I have form like this: <?php declare(strict_types=1); namespace App; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\...
Aliance's user avatar
  • 867
0 votes
1 answer
191 views

How to use UniqueEntity constraint on an encrypted field?

I'm working a project based on Symfony 4. I'm trying to make the @UniqueEntity works on an @Encrypted field, and I can't figure out how. Without the @Encrypted annotation, the @UniqueEntity ...
eti_nne's user avatar
  • 126
2 votes
1 answer
3k views

Symfony form validation: require field if another field is not empty

I use Symfony 5.3. I have a form with 3 fields that are not mapped to any entity: "reason" - text, "use_predefined" - checkbox "predefined_reason" - dropdown. I build ...
Hevyweb's user avatar
  • 440
-1 votes
1 answer
348 views

Generic Entity validation for all properties with type string in Symfony

I was wondering if there is some solution to the problem I will now say. I have plenty of entities in the project (Symfony 4.4) and I need some generic solution to validate max length of all ...
Dusan Stankovic's user avatar
0 votes
0 answers
912 views

Symfony Validator, how to combine constraints inside AtLeastOneOf to do A OR (B AND C)

For context, i'm currently working on a vanilla PHP project, no framework, mostly no POO, all of it not my choice, i'm just the duct tape guy. So, for any response involving code examples, please ...
Ajani's user avatar
  • 1
0 votes
0 answers
293 views

Quit class validator when a property fails URL constraint in Symfony 5

I have a field with a url constraint: /** * @AppAssert\AccountToMarketer */ class Account { /** * @Assert\NotBlank * @Assert\Url( * protocols = {"https"} * ) ...
Karim Mtl's user avatar
  • 1,243
1 vote
1 answer
897 views

Validation NotBlank on a non nullable field

I'm trying to validate a form that includes a field that absolutely cannot be empty or null. So in my model, it is defined like this: /** * @var string */ private $end; /** ...
arno's user avatar
  • 823
0 votes
1 answer
575 views

Validations Groups doesn't working with forms

I'm trying to setup groups validation on my symfony project. When I update an entity, I only need to validate some fields. When I create an entity, I only need to validate some other fields. Service: $...
FindL's user avatar
  • 521
4 votes
1 answer
5k views

Symfony validation constraints annotations not working

I am trying to use annotations for Symfony form validation but I can't get it to work. No matter the constraint, the form always reports as valid. I am running on PHP 7.3 with doctrine/annotations 1....
Tobias's user avatar
  • 394
0 votes
1 answer
1k views

Symfony 5.3 - FormBuilder RepeatedType - Error message is not shown in form when password not the same

I have a form with a RepeatedTyp for the password. ->add('password', RepeatedType::class, [ 'type' => PasswordType::class, 'label' => 'form.register....
Mark's user avatar
  • 79
1 vote
1 answer
1k views

How to set option for validation constraint in Symfony globally?

I need to change format for DateTime validation constraint but I want to do it globally for the whole application to not copy-paste it like this: dateFrom: - DateTime format: Y-m-d\TH:i:s.vP ...
greeflas's user avatar
  • 922
0 votes
0 answers
297 views

Symfony 5.2 Validate json_login Request

I am developing a RESTFUL API in Symfony 5.2 that allows users to authenticate with username and password in order to access it. My firewall config for this looks like: login: ...
Rob Irvin's user avatar
  • 121
0 votes
1 answer
557 views

Symfony compare form to database [duplicate]

How can I compare a form field submitted to the actual database data? If I use my repository to get a copy of the entity, it actually just gets a copy of the form submitted. I want to know if the data ...
Bradmage's user avatar
  • 1,231
0 votes
0 answers
335 views

Symfony assert callback dont work on in admin class

@Assert\Callback doesn't work and I don't understand why, what am I doing wrong? I want to check that there is at least one value in the competitionTypes field. In other entities of the project, ...
navasiolau's user avatar
0 votes
0 answers
151 views

Symfony 5 Multiple independent unique fields are not validated

I'm trying to validate unique username and email in database. Imagine this scenario in DB Users table: username email aykon [email protected] aykon94 [email protected] I have this code in User entity: ...
AykoNSvk's user avatar
0 votes
1 answer
1k views

Symfony constraint LessThan Date

I use Symfony v5.2 I've created this constraint : $constraint = new Assert\Collection([ 'firstname' => [ new Assert\NotNull(), new Assert\NotBlank() ...
JulienBlc's user avatar
  • 134
0 votes
0 answers
147 views

How can I use the built-in count constraint on a OneToMany relation to validate a new child entity?

A parent entity has a one-to-many relationship with a child entity, like this: /** * @ORM\OneToMany(targetEntity=Child::class, mappedBy="parent") */ private $children; I need to limit the ...
Don't Panic's user avatar
  • 41.8k
1 vote
2 answers
1k views

How to save null data with Api-Platform?

With Symfony 5.1 and Api Platform, I am unable to effectively handle saving NULL data. Examples for this simple entity : class Foo { /** * @var string * * @ORM\Column(type="...
Gaylord.P's user avatar
  • 1,466
0 votes
0 answers
994 views

Complex domain validation via Symfony Forms & Constraints

I have several complex Domain objects. And I use Symfony forms for validating REST requests over them. Let's assume, I have domain Banner. And I have endpoints for creating/updating the concrete ...
Aliance's user avatar
  • 867
2 votes
1 answer
1k views

Why symfony assert doesnt work with novalidation attribute on Edit Page?

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 ...
Fack Coding's user avatar
1 vote
1 answer
384 views

Symfony ValidatorComponent > AnnotationMapping in FormComponent

Im working on a project where I'm using some Symfony Components. My problem is how to make the Form Component's validation of Forms use AnnotationMapping to find the constraints. SetUp: global $loader;...
Martin's user avatar
  • 621
0 votes
1 answer
560 views

Symfony Validation of DateTime fails due to not being string?

I have the following for: formFactory->create(FormType::class); $form->submit(['startDate' => new \DateTime('2020-01-01')]); Note: if I use 'startDate' => '2020-01-01' then it works. ...
strangeQuirks's user avatar
1 vote
1 answer
4k views

Symfony validation between 2 fields

I have a change password form with 3 fields: currentPasword newPassword confirmNewPassword and I want to validate that the newPassword is not equal the current one. I can validate to check it's not ...
Hackasaurus's user avatar
0 votes
1 answer
363 views

How to Validate an EntityType field?

I want to make sure that the user chooses an element from the dropdown list. So I used * @Assert\NotBlank() in the entity file. /** * @ORM\ManyToOne(targetEntity=Bord::class, inversedBy="...
Dhia Djobbi's user avatar
  • 1,288
0 votes
1 answer
245 views

Return Symfony's validation error as success

I have a Symfony entity with @UniqueEntity annotation. I use it so I don't get double records in my database with the same email but I don't want to return to the user that the email is already in the ...
nass's user avatar
  • 347
0 votes
1 answer
367 views

Fosrestbundle form error the value is not valid entitytype

I am using FosrestBundle and in my form, I've got an entitytype on a manytomany relations. I am using postman and I have tried many differents kind of syntax to validate form but I am getting ...
El mago's user avatar
  • 11
-2 votes
1 answer
697 views

Validate an Entity through an API with Symfony

I have an entity with simple fields. Unfortunately, I can't say what are the validation constraint on the Symfony side. I must post these information on an API route. If it returns no error message, I ...
Alexandre's user avatar
  • 365
1 vote
1 answer
5k views

Api platform - invalid IRI instead of validation error

I'm using API platform for my booking application. Booking has many to 1 relationship with a department. When I create a new booking by sending a POST request with an empty string as a value for ...
fam's user avatar
  • 11
3 votes
1 answer
3k views

How to use normalizer option in Symfony constraints component

The documentation https://symfony.com/doc/4.4/reference/constraints/Length.html#normalizer states that This option allows to define the PHP callable applied to the given value before checking if it ...
inkrot's user avatar
  • 515
4 votes
1 answer
1k views

Symfony "fos_rest.request_body" converter: do not deserialize nested DTO classes

I have a OrderDto class with a nested PointDto class (array of points): class OrderDto { /** * @var PointDto[] * @Assert\All({ * @Assert\Type("App\Dto\PointDto") * }) ...
inkrot's user avatar
  • 515
0 votes
2 answers
839 views

Symfony validation not returning any violations for NotBlank

I'm using Symfony validation within my own app (not Symfony). I'm expecting it to return violations as I haven't populated the Id property: $user = new User(); $user->setId(''); //... $validator =...
Martyn's user avatar
  • 6,355
31 votes
1 answer
15k views

Why do I receive "This value should be of type string" when using a DateTime constraint on Symfony 5?

I have the following entity (only attached the relevant parts): use ApiPlatform\Core\Annotation\ApiResource; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; /*...
Toma's user avatar
  • 2,906
2 votes
1 answer
3k views

Email compliance and validation with RFC 2822, 3.6.2 in Symfony

I have an issue while validating a user email address through the Symfony Email Constraint and then trying to send an mail to this user through Swiftmailer. Let's say my user is registering with name@...
VinZ's user avatar
  • 370