Symfony4 Embed form issue - php

I'm learning php and Symfony. I made Ring entity and RingPhoto entity. I want to add a form for RingPhoto inside a form for Ring entity, so I can edit ring information and photo url; ring information will be under Ring entity and photo url will be under Ring photo.
this is Ring entity
'''
/**
* #ORM\OneToMany(targetEntity="Customize\Entity\RingPhoto", mappedBy="ring")
*/
private $ringPhoto;
public function __construct()
{
$this->ringPhoto = new ArrayCollection();
}
/**
* #return Collection|RingPhoto[]
*/
public function getRingPhoto(): Collection
{
return $this->ringPhoto;
}
'''
and this is ringPhoto Entity
'''
/**
* #ORM\ManyToOne(targetEntity="Customize\Entity\Ring", inversedBy="ringPhoto")
*/
private $ring;
public function getRings(): ?Ring
{
return $this->ring;
}
public function setRings(?Ring $ring): self
{
$this->ring = $ring;
return $this;
}
'''
and this is RingPhotoType
'''
class RingPhotoType extends AbstractType
{
/**
* {#inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('image1', FileType::class, [
'label' => 'file1'
])
->add('image2', FileType::class, [
'label' => 'file1'
])
->add('image3', FileType::class, [
'label' => 'file1'
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => RingPhoto::class,
]);
}
}
'''
this is Controller
'''
public function UpdateRing($id, Request $request){
$doct = $this->getDoctrine()->getManager();
$rn = $doct->getRepository(Ring::class)->find($id);
if(!$rn){
throw $this->createNotFoundException(
'No Ring found for id.'.$id
);
}
$form = $this->createFormBuilder($rn)
->add('product_group_id', HiddenType::class,['data'=> 1])
->add('ring_name', TextType::class)
->add('ring_type', TextType::class)
->add('ring_shape', TextType::class)
->add('size', ChoiceType::class, array('choices' => array(
'0.5'=>0.5,
'1'=>1,
'1.5'=>1.5,
'2'=>2,
'2.5'=>2.5,
'3'=>3,
'3.5'=>3.5,
'4'=>4,
)))
->add('price', IntegerType::class)
->add('ringPhoto', CollectionType::class,[
'entry_type' => RingPhotoType::class,
'allow_add' => true,
'entry_options' =>[
'label' => false,
],
'allow_add' => true,
'by_reference' => false,
'prototype' => true
])
->add('save', SubmitType::class, ['label' => 'Update'])
->getForm();
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
$ring = $form->getData();
$doct = $this->getDoctrine()->getManager();
//tell doctrine to save the product
$doct->persist($ring);
//executes the queries
$doct->flush();
return $this->redirectToRoute('test');
}
else{
return[
'form' => $form->createView(),
];
}
}
'''
and this is the twig
'''
{% extends 'default_frame.twig' %}
{% block main %}
<h3>SamplePage!!</h3>
<div>hello this is Update page</div>
{{form_start(form)}}
{{form_widget(form)}}
{{form_row(form.ringPhoto)}}
{{form_end(form)}}
{% endblock %}
'''
so it's kinda working, having no errors. But in the view, under the price, I can only see the name Ring Photo.
It does not show image1, image2, image3 from RingPhotoType.php that I can fill in :S
how can I fix this issue?

Oh I fixed it.
I added nullable=true to image1, 2, 3 in RingPhoto Entity and somehow it solved the problem

Related

Export form data to dompdf

for a few days I am blocked, if someone can help me with the good practice, I explain:
I want to retrieve data from the database: entity (expression_besoin) contains the information of a purchase with ref , requester ... and the entity besoin_article contains the items products in the previous entity, there is a OneToMany relationship between the two entities.
the objective is to retrieve the several expression needs of articles in a form in order to modify whether the quantities are necessary or to delete them, then to be able to generate a PDF file which contains all the needs and the articles which correspond to them.
Controller :
/**
* #Route("/extraire_commandes", name="export_commandes", methods={"GET","POST"})
*/
public function exportCommandes(ExBesoinRepository $exBesoinRepository, Request $request): Response
{
$datas = new FiltreBesoin();
$form = $this->createForm(FiltreBesoinType::class, $datas);
$form->handleRequest($request);
$exBesoin = $exBesoinRepository->exportCommande($datas);
$valueFournisseur = $form['fournisseur']->getData();
$formExport = $this->createFormBuilder(array('besoin' => $exBesoin));
$formExport->add('besoin', CollectionType::class, array(
'entry_type' => ExBesoinToCommandeType::class,
));
$formExport = $formExport->getForm();
$formExport->handleRequest($request);
$formValue = $formExport->getData();
if ($formExport->isSubmitted() && $formExport->isValid()) {
$html = $this->renderView('admin/besoins/epicerie/exportPdf.html.twig', [
'besoins' => $formValue,
]);
$html .= '<link rel="stylesheet" href="/build/css/app.css"> ';
$html .= '<script src="/build/vendors~js/app.js"></script><script src="/build/runtime.js"></script><script src="/build/vendors-node_modules_popperjs_core_lib_index_js-node_modules_symfony_stimulus-bridge_dist_ind-f4bfca.js"></script>';
$name = 'test';
$options = new Options();
$options->set('isHtml5ParserEnabled', true);
$options->set('isRemoteEnabled', true);
$dompdf = new Dompdf($options);
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream($name, array('Attachment' => 0));
return new Response('', 200, [
'Content-Type' => 'application/pdf',
]);
}
return $this->render('admin/besoins/epicerie/export.html.twig', [
'besoins' => $exBesoin,
'form' => $form->createView(),
'valueFournisseur' => $valueFournisseur,
//'idBesoin' => $idBesoin,
'formExport' => $formExport->createView(),
'valu'=> $formValue
]);
}
FormType
class ExBesoinToCommandeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('besoinArs', CollectionType::class, [
'entry_type' => BesoinArToCommandeType::class,
'allow_delete' => true,
//'allow_add' => false,
'prototype' => true,
'by_reference' => false,
'delete_empty' => true,
'entry_options' => [
'label' => true,
]
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => ExBesoin::class,
]);
}
public function getBlockPrefix()
{
return 'ExBesoinToCommandeType';
}
}
class BesoinArToCommandeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('article', EntityType::class, [
'class' => Article::class,
'label' => false,
'attr' =>[
'class' => 'arSelect form-control-sm',
'data-live-search' => 'true',
],
'placeholder' => 'Selectionner un article ',
'query_builder' => function (EntityRepository $er) {
$qb = $er->createQueryBuilder('a')
->innerJoin('a.category', 'c')
->where('c.is_legume = 0')
;
return $qb;
},
'group_by' => function (Article $article) {
return $article->getCategory()->getLibele();
}
])
->add('quantity', TextType::class, [
'label' => ' ',
'attr' =>[
'class' => 'quantity form-control-sm'
]
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => BesoinAr::class,
]);
}
public function getBlockPrefix()
{
return 'BesoinArToCommandeType';
}
}
Until I get my data back without problem, the getData() of the form contains all my data before the submit, but when I validate to generate my pdf file, it does not contain all the data. I use a filter system that allows me to select the expressions of need between two dates, by requester or by supplier, and the problem is linked to this filter because when I generate the pdf of the data without filter it works but when I filter my data this is where my data changes and I don't recover the filtered data, I will be grateful if someone unblocks me or tell me where the problem comes from.

Symfony Embed a Collection of Forms multiple tables

I have 3 tables/entities. I am trying to create form to persist data to all 3 table in one form. Entitities are to long that is why I haven't added here.
Entity Client I made an array collection in Client entity for other 2 entities.
protected $Clientservice;
protected $Hostingaccount;
public function __construct()
{
$this->Clientservice = new ArrayCollection();
$this->Hostingaccount= new ArrayCollection();
}
public function getClientservice()
{
return $this->Clientservice;
}
public function getHostingaccount()
{
return $this->Hostingaccount;
}
public function setClientservice($Clientservice)
{
$this->Clientservice = $Clientservice;
return $this;
}
public function setHostingaccount($Hostingaccount)
{
$this->Hostingaccount = $Hostingaccount;
return $this;
}
And I Have 3 forms:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('CustomerID',IntegerType::class)
->add('Sex',TextType::class)
->add('Name',TextType::class)
->add('FirstName',TextType::class)
->add('LastName',TextType::class)
->add('Email', EmailType::class)
->add('Invoiceemail', EmailType::class)
->add('Iban', TextType::class)
->add('Bic', TextType::class)
->add('SEPAMandateID', TextType::class)
->add('LogoUrl', TextType::class)
->add('CreationDate', DateType::class)
->add('Clientservice', CollectionType::class, array(
'entry_type' => WhmAdminClientserviceType::class
))
->add('Hostingaccount', CollectionType::class, array(
'entry_type' => WhmAdminHostingAccountType::class
))
->getForm();
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Client::class
));
}
Clientservice form
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('Description',TextType::class);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Clientservice::class
));
}
Hostingaccount form:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('Domain',TextType::class)
->add('Domainip',IntegerType::class)
->add('UserName',TextType::class)
->add('Owner',TextType::class);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => Hostingaccount::class
));
}
In my controller I have the code like this:
public function AddWhmAdminAction(Request $request)
{
$Client = new Client();
$form = $this->createForm(WhmAdminType::class, $Client);
$form->add('submit', SubmitType::class, array(
'label' => 'Create',
'attr' => array('class' => 'btn btn-default pull-left')
));
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($Client);
$em->flush();
$this->get('session')->getFlashBag()->add('green', 'Product created!');
return $this->redirectToRoute('whmAdmin');
// flash msg
}
//return $form->createView();
$build['form'] = $form->createView();
return $this->render('whm/WhmAdminForm.html.twig', $build);
}
and in my view
{{ form_start(form) }}
{% for flashMessage in app.session.flashbag.get('green') %}
{{ flashMessage }}
{% endfor %}
{{ form_end(form) }}
I followed http://symfony.com/doc/current/form/form_collections.html and this is how far I got.
My form only shows the fields from Client. It does not shows field from Clientservice and hostingaccount. How can I show the fields from clientservice and hostingaccount in the same form as Client.
If the Clientservice and Hostingaccount are in OneToOne or ManyToOne relationship then change:
->add('Clientservice', CollectionType::class, array(
'entry_type' => WhmAdminClientserviceType::class
))
->add('Hostingaccount', CollectionType::class, array(
'entry_type' => WhmAdminHostingAccountType::class
))
to:
->add('Clientservice', WhmAdminClientserviceType::class)
->add('Hostingaccount', WhmAdminHostingAccountType::class)
Otherwise leave your form builders and read about adding and removing items in collection type.

Symfony 2 persiting 2 entities from form using ID generated from first entity

I have a form that collects data from two related entities 'Jobs' and 'Scope'. Jobs data adds successfully to the database, but i can't get the scope entity to add which also requires the unique ID that was created from the jobs entry. I'm using doctrine by the way.
Here is jobsType:
class jobsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('jobNumber', null, array('label' => 'Job Number','attr' => array('placeholder'=>'Code used for job')))
->add('description', null, array('label' => 'Job Description',))
;
$builder->add('scopes', new scopeType())
;
}
public function getName()
{
return 'jobs';
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Baker\TimeSlipBundle\Entity\Jobs',
));
}
}
Here is scopeType
class scopeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('description', 'entity', array('label' => 'Scope', 'required' => false,
'class' => 'BakerTimeSlipBundle:Scope',
'query_builder' => function(EntityRepository $er){
return $er->createQueryBuilder('s')
->orderBy('s.description', 'asc');
},
'property' => 'description',
'multiple' => false,
'expanded' => false,
'empty_value' => false,
'attr' => array('class' => 'form-inline'),
'label_attr' => array('class' => 'required')
))
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Baker\TimeSlipBundle\Entity\Scope',
));
}
public function getName()
{
return 'scope';
}
}
Here is my controller, i think the problem here is that i'm not passing the scope() instance to the form builder. Which i'm not sure how to do. The entity is mapped correctly.
class JobsController extends Controller
{
public function indexAction($limit, Request $request)
{
$jobs= new Jobs();
$scope = new Scope();
$fname=$limit;
$form = $this->createForm(new JobsType(),$jobs, array(
'method' => 'POST',
));
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($jobs);
$em->persist($scope);
$em->flush();
return $this->redirectToRoute('company',array ('limit' =>'Job Submitted Successfully'));
}
return $this->render(
'BakerTimeSlipBundle:Jobs:index.html.twig',
array('fname' => $fname,
'form' => $form->createView()
)
);
}
}
}
Any help here would be greatly appreciated. Below is listed the error message when I try to enter the scope:
An exception occurred while executing 'INSERT INTO Scope (description, jobsId, jobsid) VALUES (?, ?, ?)' with params [null, null, null]:
SQLSTATE[42000]: Syntax error or access violation: 1110 Column 'jobsId' specified twice
The problem here is the $jobs object you link to your form has no relation with the $scope object. So when you try to persist $jobs, Doctrine has no idea $scope it had to persist.
Just try this :
$jobs= new Jobs();
$scope = new Scope();
$jobs->setScope($scope);
Then, in your Jobs entity, on the annotation above $scopes, make sure you have cascade={"persist"} (but you must already have it because Doctrine tries to persist, and that's where the error is thrown), and you should be good to go.
Hope this helps

Symfony2 implement a form for OneToOne relation

I am trying to implement a one to one relation. Each User can be affected at a building (Etablissement for me). A building can have many people but each people can be affected at one building at most.
I have this error :
ContextErrorException: Catchable Fatal Error: Argument 1 passed to Intranet\UserBundle\Entity\User::setUserEtab() must be an instance of Intranet\RhBundle\Entity\Etablissement, array given, called in C:\wamp\www\projet\vendor\symfony\symfony\src\Symfony\Component\PropertyAccess\PropertyAccessor.php on line 360 and defined in C:\wamp\www\projet\src\Intranet\UserBundle\Entity\User.php line 322
The line 322 of User.php is :
public function setEtablissement(\Intranet\RhBundle\Entity\Etablissement $etablissement = null)
It occurs at the line $form->handleRequest($request); of my controller. This is my controller :
public function editerAction(Request $request, User $user){
$form = $this->createForm(new EditerFormType, $user);
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
die("ici");
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($user);
$this->get('session')->getFlashBag()->add('success', "L'utilisateur ". $user->getNom() ." ". $user->getPrenom() . " a été édité avec succès !");
$em->flush();
return $this->redirect($this->generateUrl('intranet_rh_homepage'));
}else
$this->get('session')->getFlashBag()->add('danger', "Erreur de formulaire !");
}
return $this->render('IntranetRhBundle:User:editer.html.twig',array('user' => $user, 'form' => $form->createView()));
}
The die doesn't work. Before adding the form, it was working.
This is the EditForm :
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', 'email', array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))
->add('nom', 'text')
->add('prenom', 'text')
->add('naissance','date',array(
'widget' => 'single_text',
'format' => 'dd/MM/yyyy',
'attr' => array('class' => 'date', 'readonly' => 'readonly')
))
->add('sexe', 'choice', array(
'choices' => array('Homme' => 'Homme', 'Femme' => 'Femme'),
'multiple' => false
))
->add('etablissement', new UserEtabType())
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array('data_class' => 'Intranet\Userbundle\Entity\User'));
}
This is my UserEtab form :
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('etablissement', 'entity', array('class' => 'IntranetRhBundle:Etablissement', 'property' => 'nom', 'empty_value' => 'Aucun', 'empty_data' => -1, 'required' => false))
;
}
And my relation on User entity :
/**
* #ORM\OneToOne(targetEntity="Intranet\RhBundle\Entity\Etablissement", cascade={"persist", "remove"})
**/
private $etablissement;
The form's view is okay, there is a select list with all the building and an empty value. But when I post, I have this error I can't understand and solve.
I have the setter and getter if User entity :
/**
* Set Etablissement
*
* #param \Intranet\RhBundle\EntityEtablissement $etablissement
* #return User
*/
public function setEtablissement(\Intranet\RhBundle\Entity\Etablissement $etablissement = null)
{
$this->etablissement = $etablissement;
return $this;
}
/**
* Get Etablissement
*
* #return \Intranet\RhBundle\Entity\Etablissement
*/
public function getEtablissement()
{
return $this->etablissement;
}
But when I var_dump $request->get('user')->get('etablissement') it doesn't work :
Error: Call to undefined method Intranet\UserBundle\Entity\User::get() in C:\wamp\www\projet\src\Intranet\RhBundle\Controller\UserController.php line 69
And the building doesn't appear in var_dump of $request->get('user').
EDIT :
I don't have a setDefaultOptions method for my UserEtabType because I don't know what I have to do. I tried to implements it but I have this kind of error :
The form's view data is expected to be an instance of class Intranet\UserBundle\Entity\User, but is an instance of class Proxies__CG__\Intranet\RhBundle\Entity\Etablissement. You can avoid this error by setting the "data_class" option to null or by adding a view transformer that transforms an instance of class Proxies__CG__\Intranet\RhBundle\Entity\Etablissement to an instance of Intranet\UserBundle\Entity\User.
For the new UserEtabType :
namespace Intranet\UserBundle\Form\Type;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class UserEtabType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('etablissement', 'entity', array('class' => 'IntranetRhBundle:Etablissement', 'property' => 'nom', 'empty_value' => 'Aucun', 'empty_data' => -1, 'required' => false))
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array('data_class' => 'Intranet\UserBundle\Entity\User'));
}
public function getName()
{
return 'intranet_userbundle_useretablissementtype';
}
}
Can you show the new UserEtabType() class ?
EDIT 1 : Try putting this line :
->add('etablissement', 'entity', array('class' => 'IntranetRhBundle:Etablissement', 'property' => 'nom', 'empty_value' => 'Aucun', 'empty_data' => -1, 'required' => false));
in the main EditForm
EDIT 2:
plus be careful :
$resolver->setDefaults(array('data_class' => 'Intranet\UserBundle\Entity\User'));
must be
$resolver->setDefaults(array('data_class' => 'Intranet\UserBundle\Entity\Etablissement'));
in your UserEtabType() class
Are you getting this error when you try to insert a record ? Or before that. For your information, setUserEtab() in the User entity expects an object of Etablissement, because of the one-to-one relationship. Passing the value of an array is not sufficient. Try passing the object of Etablissement it self (the selected object after performing dql).
Hope this helps someone.
Cheers!

Symfony2 Form Collection allow_add and allow_delete null error (Silex)

I've run into a problem when following the Symfony cookbook for form collections with add/remove. See: http://symfony.com/doc/current/cookbook/form/form_collections.html
Now, for some reason, if I dynamically add a form row but don't fill in any of its fields, I get the following error:
ContextErrorException: Catchable Fatal Error: Argument 1 passed to Project::addTask() must be an instance of Task, null given in D:\web_workspace\wedding\src\testapp.php line 82
I would like people to be able to have blank rows in the form which will just get ignored. For example, if you click "Add Task" a few times, but don't fill in the last row, the form should still be submitted, and the last row should be ignored.
I've created a very simple Silex demo that fits in just a couple of files. I'll highlight it here, but the full example is here, and can be run by just adding Silex via composer: https://gist.github.com/mattsnowboard/7065865
I have the following Models (just Project which has a description and a collection of Tasks)
class Task
{
protected $name;
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
return $this;
}
}
class Project
{
protected $description;
protected $tasks;
public function __construct()
{
$this->tasks = array();
}
public function getDescription()
{
return $this->description;
}
public function setDescription($description)
{
$this->description = $description;
return $this;
}
public function getTasks()
{
return $this->tasks;
}
public function addTask(Task $task)
{
if (!is_null($task) && !in_array($task, $this->tasks)) {
$this->tasks[] = $task;
}
return $this;
}
public function removeTask(Task $task)
{
if (!is_null($task)) {
$this->tasks = array_diff($this->tasks, array($task));
}
return $this;
}
}
My forms are as follows
class TaskType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', 'text', array(
'required' => false
));
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => '\Task',
));
}
public function getName()
{
return 'task';
}
}
class ProjectType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('description', 'text', array())
->add('tasks', 'collection', array(
'type' => new TaskType(),
'allow_add' => true,
'by_reference' => false,
'allow_delete' => true,
'required' => false
))
->add('submit', 'submit')
;
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => '\Project',
));
}
public function getName()
{
return 'project';
}
}
The controller adds some test data to the form and just prints the data when it is submitted:
$app->match('/', function (Request $request) use ($app) {
$project = new Project();
// dummy code
$task1 = new Task();
$task1->setName('A Task');
$project->addTask($task1);
// end dummy code
$form = $app['form.factory']->create(new ProjectType(), $project);
$form->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();
$debug = print_r($data, true);
echo $debug;
}
return $app['twig']->render('test.html.twig', array(
'form' => $form->createView(),
));
})
->method('GET|POST');
The view is mostly this, and the javascript sample from the cookbook
{{ form_start(form) }}
{{ form_row(form.description) }}
<h3>Tags</h3>
<ul class="tasks" data-prototype="{{ form_widget(form.tasks.vars.prototype)|e }}">
{# iterate over each existing tag and render its only field: name #}
{% for task in form.tasks %}
<li>{{ form_row(task.name) }}</li>
{% endfor %}
</ul>
{{ form_widget(form.submit) }}
{{ form_end(form) }}
Am I just missing something? Is this a bug? I feel like this example which is very close to the cookbook should work pretty easily...
Updated: Removing "allow_deleted" doesn't actually fix this.
Sorry, I figured it out, the collection type shouldn't have 'required' => false
$builder->add('description', 'text', array())
->add('tasks', 'collection', array(
'type' => new TaskType(),
'allow_add' => true,
'by_reference' => false,
'allow_delete' => true,
'required' => false
))
Should be
$builder->add('description', 'text', array())
->add('tasks', 'collection', array(
'type' => new TaskType(),
'allow_add' => true,
'by_reference' => false,
'allow_delete' => true
))

Categories