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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:59:33+00:00 2026-06-11T18:59:33+00:00

I’ve been stuck on this for days and tried all the solutions I could

  • 0

I’ve been stuck on this for days and tried all the solutions I could find online but no luck.

I have a Student linked to many Transfers. Each transfer is linked to a Classe.

To make the form I use the following classes : StudentType, TransferType.

The StudentType form classe had a field of type TransferType. Codes below.

StudentType.php

<?php
// src/PS/PSchoolBundle/Form/StudentType.php

namespace PS\PSchoolBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use PS\PSchoolBundle\Entity\Responsible;
use PS\PSchoolBundle\Entity\AuthorizedPerson;
use PS\PSchoolBundle\Entity\Transfer;

class StudentType extends AbstractType
{
    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('subNumber', 'text', array('required'  => false))
            ->add('subDate', 'date', array(
                        'required'  => false,
                        'widget' => 'single_text',
                        'format' => 'dd/MM/yyyy',
                        'attr' => array('class' => 'datepicker')
                    ))
            ->add('lastName', 'text')
            ->add('firstName', 'text')
            ->add('lastNameSecondLanguage', 'text', array('required'  => false))
            ->add('firstNameSecondLanguage', 'text', array('required'  => false))
            ->add('birthDate', 'date', array('required'  => false,
                        'widget' => 'single_text',
                        'format' => 'dd/MM/yyyy',
                        'attr' => array('class' => 'datepicker')
                    ))
            ->add('birthPlace', 'text', array('required'  => false))
            ->add('birthPlaceSecondLanguage', 'text', array('required'  => false))
            ->add('gender', 'choice', array('choices' => array('' => 'Veuillez choisir', 'm' => 'Garçon', 'f' => 'Fille')))
            ->add('nationality', 'text', array('required'  => false))
            ->add('homeLanguage', 'text', array('required'  => false))
            ->add('bloodType', 'text', array('required'  => false))
            ->add('familySituation', 'choice', array('required'  => false,
                                                            'choices' => array(
                                                            '' => 'Veuillez choisir',
                                                            'm' => 'Mariés',
                                                            'd' => 'Divorcés',
                                                            'w' => 'Veuve',
                                                            'a' => 'Autre')))
            ->add('schoolStatusBefore', 'choice', array('required'  => false, 'choices' => array('' => 'Veuillez choisir', 's' => 'Scolarisé', 'ns' => 'Non scolarisé')))
            ->add('remark', 'textarea', array('required'  => false))
            ->add('responsibles', 'collection', array('type' => new ResponsibleType,
                                                      'prototype' => true,
                                                      'allow_add' => true,
                                                      'allow_delete' => true))
            ->add('authorizedPersons', 'collection', array('type' => new AuthorizedPersonType,
                                                      'prototype' => true,
                                                      'allow_add' => true,
                                                      'allow_delete' => true))

            ->add('transfers', 'collection', array('type' => new TransferType,
                                                      'prototype' => true,
                                                      'allow_add' => true,
                                                      'allow_delete' => true));
    }

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

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'PS\PSchoolBundle\Entity\Student'
        );
    }
}

TransferType.php

<?php
// src/PS/PSchoolBundle/Form/TransferType.php

namespace PS\PSchoolBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilder;
use PS\PSchoolBundle\Entity\Transfer;
use Doctrine\ORM\EntityRepository;

class TransferType extends AbstractType
{

    public function buildForm(FormBuilder $builder, array $options)
    {
        $builder
            ->add('reason', 'choice', array(
                        'choices' => array('success' => 'Réussite', 'failure' => 'Échec'),
                        'required'  => false
                        ))
            ->add('date', 'date', array(
                        'widget' => 'single_text',
                        'format' => 'dd/MM/yyyy',
                        'attr' => array('class' => 'datepicker')
                    ))
            ->add('school', 'text', array('required'  => false))
            ->add('classe', 'entity', array('class' => 'PSPSchoolBundle:Classe', 'property' => 'name'));
    }

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

    public function getDefaultOptions(array $options)
    {
        return array(
            'data_class' => 'PS\PSchoolBundle\Entity\Transfer'
        );
    }
}

When I added the “classe” field to the TransferType, instead of showing the form, I get this error thrown :

Entities passed to the choice field must be managed 500 Internal
Server Error – FormException

Please note that I have tried TransferType and the form shows correctly with classe choice field populated. This problem only arises when I use the TransferType and the StudentType together.

Thanks

Edit – Below is the action of the controller that generates the form:

public function byIdEditAction($id)
{
        $em = $this->getDoctrine()->getEntityManager();

        if(!$student = $em->getRepository('PSPSchoolBundle:Student')->find($id))
        {
        throw $this->createNotFoundException('Student[id='.$id.'] does not exist.');
        }

        $form        = $this->createForm(new StudentType(), $student);
        $formHandler = new StudentHandler($form, $this->get('request'), $em);

        if($formHandler->process())
        {
            $this->get('session')->setFlash('wehappy', "L'élève a été mis à jour.");
            return $this->redirect($this->generateUrl('_studentsbyidshow', array('id' => $student->getId())));
        }

        return $this->render('PSPSchoolBundle:Student:edit.html.twig', array(
            'form' => $form->createView(),
            'student' =>  $student
    ));
}
  • 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-11T18:59:34+00:00Added an answer on June 11, 2026 at 6:59 pm

    My problem was actually linked to the fact that I’m using a StudentType that has an entity field (Transfer) which itself has an entity field (Classe).
    The transfer object that was linked to the Student object did not have a Classe linked to it and thus I had that exception thrown complaining about the fact that the Classe object, that needs to be added to the Classes choice field was not managed. That means that it has to be managed by the entity manager. In other words, it had to be coming from the database.

    There are two ways to fix this problem :
    The obvious one was to fix the link that was missing on the database as that relation is set to not nullable on Doctrine.
    The second way was to create a default Classe object and pull it from the data base, then assign it to the transfer like so :

    if(!$classe = $em->getRepository('PSPSchoolBundle:Classe')->find(-2))
        {
            throw $this->createNotFoundException('Classe[id='.$id.'] does not exist.');
        }
    
        $transfer->setClasse($classe);
    

    before actually creating the form using the StudentType…

    Hope this helps somebody.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
This could be a duplicate question, but I have no idea what search terms
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from

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.