8000 [Form] Form::bindRequest will fail on form with only one field · Issue #2553 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Form] Form::bindRequest will fail on form with only one field #2553

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
Burgov opened this issue Nov 3, 2011 · 3 comments
Closed

[Form] Form::bindRequest will fail on form with only one field #2553

Burgov opened this issue Nov 3, 2011 · 3 comments
Milestone

Comments

@Burgov
Copy link
Contributor
Burgov commented Nov 3, 2011

I created a form using the form factory which essentially contains only one field:

$builder = $this->container->get('form.factory')->createBuilder(
    'email', 
    $person->getEmail()
);

Trying to bind this form to the post triggers the following error:

Warning: array_replace_recursive() [function.array-replace-recursive]: Argument #1 is not an array in D:\workspace\09_061_Shifter_RAI\vendor\symfony\src\Symfony\Component\Form\Form.php line 583

@ericclemmons
Copy link
Contributor

Hmmm... this looks weird to me. Usually you create a builder that maps to your model, then add subsequent fields.

For example, see the Controller#createFormBuilder shortcut:

https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php#L137

Additionally, see the documentation:

http://symfony.com/doc/2.0/book/forms.html#building-the-form

Can you try that first & see if that fixes your issue?

@Burgov
Copy link
Contributor Author
Burgov commented Nov 4, 2011

ericclemmons, indeed it is really easy to workaround this one, but I still feel that the issue addresses a normal use case, which should probably be fixed.

Workaround:
$builder = $this->createFormBuilder(array('email'=>$person->getEmail()))->add('email', 'email');
$form = $builder->getForm();

< 8000 div class="TimelineItem js-comment-container" data-gid="MDEyOklzc3VlQ29tbWVudDI2MzE1OTY=" data-url="/symfony/symfony/comments/MDEyOklzc3VlQ29tbWVudDI2MzE1OTY=/partials/timeline_issue_comment" >
@ericclemmons
Copy link
Contributor

The fundamental part of the Form component is that it's binding representation via fields to a model.

When you try to create a form using just email, you're not working with a model but with a property.

The supported use-case would be

$form = $this->createFormBuilder($person)->add('email', 'email')->getForm();

There's no need to create an associative array of whitelisted properties, as that's what the DataMapper portion of the form does automatically when bound.

If you still believe this is a bug, it's better to ping beberlei about it, as he's the author of this component.

Cheers!

fabpot added a commit that referenced this issue Feb 10, 2012
Commits
-------

6a45a41 [Form] Fixed Form::bindRequest() when used on a form without children

Discussion
----------

[Form] Fixed Form::bindRequest() when used on a form without children

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #2553
Todo: -

![Travis Build Status](https://secure.travis-ci.org/bschussek/symfony.png?branch=issue2553)
@fabpot fabpot closed this as completed Feb 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0