Created
July 22, 2015 14:43
-
-
Save albertski/ca28218ac1374c286e90 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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