Closed
Description
Most of RESTFull API's just ignores extra data submitted to their actions because in some cases doesn't make any sense show an error, mainly when you are working with unnamed forms. When you don't have subforms, a terrible workaround with problematic performance is:
$data = $request->request->all(); // ->get($form->getName());
$children = $form->all();
$data = array_intersect_key($data, $children);
$form->bind($data);
So, I suggest introducing a new simple option in the form configuration:
$factory->create('acme.form', $model, array('ignore_extra_data' => true));
// Mark the form with an error if it contains extra fields
if (false == $config->getOption('ignore_extra_data') && count($form->getExtraData()) > 0) {
$this->context->addViolation(
$config->getOption('extra_fields_message'),
array('{{ extra_fields }}' => implode('", "', array_keys($form->getExtraData()))),
$form->getExtraData()
);
}
Once the default value is false
, it'll not cause BC breaks.
If you agree, I'll be happy in submit a PR.