Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Form] Add allow_extra_fields option on forms #8133

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

Merged
merged 1 commit into from
Jun 13, 2014
Merged
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
add allow_extra_fields option
  • Loading branch information
felds committed May 24, 2013
commit c6f3dd6a85eb5893df94ab2c9646842b53e47f29
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function validate($form, Constraint $constraint)
}

// Mark the form with an error if it contains extra fields
if (count($form->getExtraData()) > 0) {
if (!$config->getOption('allow_extra_fields') && count($form->getExtraData()) > 0) {
$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 @@ -67,6 +67,7 @@ public function setDefaultOptions(OptionsResolverInterface $resolver)
'cascade_validation' => false,
'invalid_message' => 'This value is not valid.',
'invalid_message_parameters' => array(),
'allow_extra_fields' => false,
'extra_fields_message' => 'This form should not contain extra fields.',
'post_max_size_message' => 'The uploaded file was too large. Please try to upload a smaller file.',
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,28 @@ public function testViolationIfExtraData()
$this->validator->validate($form, new Form());
}

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

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

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

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

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

/**
* @dataProvider getPostMaxSizeFixtures
*/
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.