symfony/symfony — Issue #2697: Missing form fields in submission set entity attributes to NULL 
Author: leevigraham
Created: 2011-11-23 06:01:02+00:00
State: open

I created a FormType that has all the attributes of my entity like so:

add('description')
->add('duration')
->add('timerStartedAt')
->add('startedAt')
;
}

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

I have a requirement just to update the description attribute of an existing Activity on the front end like so:

{{ form_errors(activity.edit_activity_form) }}
{{ form_widget(activity.edit_activity_form._token) }}

{{ form_label(create_activity_form.description) }}
{{ form_widget(create_activity_form.description) }}

Edit Activity

However submitting this form and binding the request results in the non-submitted fields (duration, timerStartedAt, startedAt) being set to NULL.

/**
* Updates an existing Activity entity.
* @Route("/activity/{id}", name="put_activity")
* @Method("put")
*/
public function putActivityAction($id)
{
$em = $this->getDoctrine()->getEntityManager();
$activity = $em->getRepository('Newism\ActivityBundle\Entity\Activity')->find($id);
$editForm = $this->createForm(new ActivityType(), $activity);
$request = $this->getRequest();
$editForm->bindRequest($request);

var_dump($activity);
exit;

// ....

Looking at the Form::bind() method this looks like the intended behaviour although I think this is an issue. If a field is not submitted and the Entity was previously bound shouldn't the existing values be used?