Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:27:34+00:00 2026-06-13T23:27:34+00:00

I spent a lot of time to find a solution to this problem but

  • 0

I spent a lot of time to find a solution to this problem but I don’t find the correct solution

I have a User entity that can contain multiple entity Address. The validation of the User entity should function like this:

  • User must have at least two entities Address
  • User must have a maximum of three entities Address
  • Address has its own validation constraints

Both entities have their formType and Address is a CollectionType in User formType.

Currently, I create in my User controller, 3 Address that appear correctly in the view. I use ‘Assert\Count’ with ‘min=2’ to validate the form in the entities. In my controller, I filter the query to remove the Address which have not been completed, then I validate the form. This approach is not correct. I am unable to display the 3 addresses if the form is not valid, I have only the addresses that have been completed. In addition, errors are not available in the fields when I made ​​the view with Twig

Ideally logic would be as follows: the Address are validated and only the valid Address are taken into account by User. User checks its validation constraints are respected then the User entity is stored in the database. Simple, right ? (… well that’s what I thought)

Do you have any ideas or blog posts that cover my problem?

EDIT (to answer question in comment)

In the User entity

<?php
//...
* @Assert\Count(
*      min=2,
*      minMessage="user_form_not_enough_addresses",
*      max=3,
*      maxMessage="user_form_too_much_addresses"
* )
*/
private $addresses;
//...

In the User controller (when I filter the request)

//...

// Removing not completed addresses from request
$this->_filterRequest($request);

$userType = new UserType();
$user = new User();

$userForm = $request->get($userType->getName());
foreach ($userForm['addresses'] as $address) {
    $user->getAddresses()->add(new Address());
}

$form = $this->createForm($userType, $user);
$form->bind($request);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:27:35+00:00Added an answer on June 13, 2026 at 11:27 pm

    After some research the only acceptable solution was to use Symfony events.

    We must distinguish between two parts: validation and data recording. In both parts, you must validate addresses using the validator and do something based on errors that are found.

    In the case of validation, you must copy the file validation ValidationListener.php then use the services to match your file. Then simply customize the validation mechanism. The objective is to only display addresses that are not valid but that are required or not required but with some fields that are filled, just search the different cases and use ViolationMapperInterface::mapViolation() when the error should be displayed.

    In the case of data recording, just filter invalid addresses to be sure they are not taken into consideration by Doctrine (which would cause an SQL error otherwise)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent a LOT of time browsing the web to find a solution
I have spent a lot of time on google but couldn't find something useful.
I have spent a lot of time researching this, but perhaps someone point me
I have spent a lot of time looking for a solution, but could not
I spent a lot of time reading and still can't find the best solution.
I've spent a lot of time googling this and testing in my program, but
I have struggled a lot spent quiet a lot of time but unable to
spent a lot of time for searching the solution to my task, but i'm
I spent lot of time searching for it, but couldnt find. Dont blast me
I already spent a lot of time trying to solve this problem, I've seen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.