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 9215767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:16:35+00:00 2026-06-18T02:16:35+00:00

I have two models, Lesson and Evaluation. Each lesson can have multiple evaluations. I

  • 0

I have two models, Lesson and Evaluation. Each lesson can have multiple evaluations.

I am trying to set up an embedded form which will allow users to enter all of this data at the same time.

It works fine for adding and editing data, however I have a problem if I try to remove an evaluation.

For example, I have a lesson with three evaluations attached. I then submit with form again but with one of those removed.

In the controller, I first get the lesson being edited, then get its evaluations and loop through them, printing the ids. Three ids are printed as expected.

Next, I bind the request to the form and check if it is valid. I then get the evaluations again and loop through them once more to check that they’ve been removed, however all three ids were still there!

If I print the raw POST data, there are only two.

Can anyone see what I have done wrong?

Here is my controller code:

public function editAction($id = NULL)
{
    $lesson = new Lesson;

    if ( ! empty($id))
    {
        $lesson = $this->getDoctrine()
                    ->getRepository('LessonBundle:Lesson')
                    ->find($id);
    }

    foreach ($lesson->getEvaluations() as $evaluation)
    {
        print_r($evaluation->getId());
        print_r('<br />');
    }


    $form    = $this->createForm(new LessonType(), $lesson);
    $request = $this->getRequest();

    if ($request->getMethod() == 'POST') {

        $form->bindRequest($request);

        if ($form->isValid()) {

            foreach ($lesson->getEvaluations() as $evaluation)
            {
                print_r($evaluation->getId());
                print_r('<br />');
            }
            die();

            $em = $this->getDoctrine()->getEntityManager();
            $em->persist($lesson);
            $em->flush();
        }
    }
}

Here is my lesson form:

class LessonType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('evaluations', 'collection', array(
                                            'type' => new EvaluationType(),
                                            'allow_add' => true,
                                            'by_reference' => false,
                                            'allow_delete' => true,
                                            ));
    }

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'LessonBundle\Entity\Lesson',
        );
    }

    public function getName()
    {
        return 'Lesson';
    }
}

And finally, my Evaluation form:

class EvaluationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('report');
    }

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'LessonBundle\Entity\Evaluation',
        );
    }

    public function getName()
    {
        return 'Evaluation';
    }
}

Any advice appreciated.

Thanks.

  • 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-18T02:16:36+00:00Added an answer on June 18, 2026 at 2:16 am

    I got around in by using:

    $lesson = $form->getData();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models, TreeNode and User. Each user has_one TreeNode, which is the
I have two models, a code model and a tag model which are linked
I have a nested two models nested in a form partial but the field_for
I have two models, one called Notes and one called Comments. Comments can be
I have two models that are related to each other. For a contrived example,
I have two models: Users and Projects. The idea is that Users can follow
I have two models which are linked in a has_one / belongs_to association; Computer
I have two models: Client and Invoice. Every client can have many invoices, every
I have two models which are linked in a has_one / belongs_to association; Computer
I am trying to set up some embedded forms using this guide. I have

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.