Skip to content

Instantly share code, notes, and snippets.

@albertski
Created July 22, 2015 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertski/ca28218ac1374c286e90 to your computer and use it in GitHub Desktop.
Save albertski/ca28218ac1374c286e90 to your computer and use it in GitHub Desktop.
<?php
/**
* Process the form.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* @param \Symfony\Component\Form\FormInterface $form
* @param boolean $removeExtraFields
*/
private function processForm(Request $request, FormInterface $form, $removeExtraFields = FALSE)
{
$data = json_decode($request->getContent(), true);
// If you send extra fields to a form it will give you an error. This will
// remove the extra fields.
if ($removeExtraFields) {
$formFields = $form->all();
$data = array_intersect_key($data, $formFields);
}
$clearMissing = $request->getMethod() != 'PATCH';
$form->submit($data, $clearMissing);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment