Skip to content

[Form] Added a configuration that allow form extra data #9377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
// According to RFC 2396 (http://www.ietf.org/rfc/rfc2396.txt)
// section 4.2., empty URIs are considered same-document references
'action' => '',
'allow_extra_fields' => false,
));

$resolver->setAllowedTypes(array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function validate($form, Constraint $constraint)
}

// Mark the form with an error if it contains extra fields
if (count($form->getExtraData()) > 0) {
if (count($form->getExtraData()) > 0 && !$config->getOption('allow_extra_fields', false)) {
$this->context->addViolation(
$config->getOption('extra_fields_message'),
array('{{ extra_fields }}' => implode('", "', array_keys($form->getExtraData()))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,25 @@ public function testViolationIfExtraData()
$this->validator->validate($form, new Form());
}

public function testNoViolationIfExtraDataAllowed()
{
$context = $this->getMockExecutionContext();

$form = $this->getBuilder('parent', null, array('allow_extra_fields'=>true))
->setCompound(true)
->setDataMapper($this->getDataMapper())
->add($this->getBuilder('child'))
->getForm();

$form->submit(array('foo' => 'bar'));

$context->expects($this->never())
->method('addViolation');

$this->validator->initialize($context);
$this->validator->validate($form, new Form());
}

/**
* @dataProvider getPostMaxSizeFixtures
*/
Expand Down