Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

[2.3] [Form] Implemented form processors#6522

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 5 commits intosymfony:masterfromwebmozart:issue5493
Apr 19, 2013

Conversation

@webmozart
Copy link
Contributor

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: partially#5493
Todo: -
License of the code: MIT
Documentation PR:symfony/symfony-docs#2092

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This can be moved afterif below.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I mean line above 😮

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

That's a rather pointless micro optimization.

@webmozart
Copy link
ContributorAuthor

Added the helpersform_start() andform_end() which were missing before.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

The example inBefore andAfter will probably confuse people that use theelse part of the condition. So it should make clear that one must checkisBound before falsely adding flash messages about an invalid form (that is not even bound).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed

@webmozart
Copy link
ContributorAuthor

We discussed in#5493 whetherform_end() should also implyform_rest().@Tobion made the valid point that people might not always want to render all fields. I think this is an edge case tough, so I propose to implyform_rest() by default and make it possible to deactivate this using a variablerender_rest.

{{ form_start(form) }}   {# ... #}{{ form_end(form) }}

or

{{ form_start(form) }}   {# ... #}{{ form_end(form, { 'render_rest': false }) }}

What do you think?

@webmozart
Copy link
ContributorAuthor

Another question that remains to be answered:

With the current implementation, the attributes passed in theattr option are rendered both in the<form> tag (new) and in the<div>/<table> tag of the form (for BC).

$form = $this->createForm('my_form', $formData, array(    'attr' => array(        'id' => 'foo',        'class' => 'bar',    ),));
{{ form_start(form) }}    {{ form_widget(form) }}    <input type="submit">{{ form_end(form) }}-><form>    <div>        <!-- rows -->    </div>    <input type="submit"></form>

Solutions that come to mind:

(a) Move the rendering of the attributes from the<div>/<table> tag to the<form> tagfor the root form. This breaks BC because theform_widget() call for the root form does not output the attributes anymore then. Nested forms are not affected.

<form>    <div><!-- no attrs! -->        <!-- rows -->    </div>    <input type="submit"></form>

(b) Don't render a<div> tagfor the root form and do as in (a) for the table layout. This obviously also breaks BC. Nested forms are not affected.

<form>    <!-- rows -->    <input type="submit"></form>

(c) Don't render any attributes in the<form> tag. Maintains full BC.

<form>    <div>        <!-- rows -->    </div>    <input type="submit"></form>

Opinions?

While (c) is the best solution from a BC point of view, I think it is rather unintuitive. As a newcomer, if I put a "class" attribute on a form, I would expect it to be on the outermost<form> tag, not on some<div> within.

(a) and (b), on the other hand, break BC for those people that useform_widget() to render the complete form. I don't know how many people would be affected by this,this poll tries to gather some data about that. IMO both (a) and (b) are more intuitive and future-proof.

@webmozart
Copy link
ContributorAuthor

Added the helperform() to prototype a complete form:

{{ form(form) }}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

you should also merge `$_FILES`` to handle file uploads in the native processor and be consistent with the Request one

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed. Had to copy over some code fromFileBag for that.

@Tobion
Copy link
Contributor

@bschussek I think{{ form_end(form, { 'render_rest': false }) }} is fine.

And to the question about attributes: I think we shouldnot maintain BC here with c) because attributes are better applied to the parent. Using CSS you can easily select the child with#formid > div but not the other way round which would make it impossible the style the form element.
So I would say a) or b) is better than c). And a) is better than b) because in HTML 4 Strict<input> element must be within a block element like<div>. So b) would not produce valid HTML 4 Strict. This restriction is not there in HTML5 anymore but yourid validation also uses the HTML4 paradigm.
All in all, IMO the best solution is a).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

As mentioned, inputs must be wrapped with a block level element like<div> to be valid HTML4 Strict. So this would need to be changed too.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This will be fixed by#6528.

@webmozart
Copy link
ContributorAuthor

And a) is better than b) because in HTML 4 Strict<input> element must be within a block element like<div>. So b) would not produce valid HTML 4 Strict.

@Tobion This is not correct. With (b), each row would still be wrapped in a<div>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

you should document the method in the interface

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks, fixed

@webmozart
Copy link
ContributorAuthor

I propose to postpone the question about the wrapping<div> to a future PR.

@fabpot This PR should be mergeable.

@webmozart
Copy link
ContributorAuthor

Updated the documentation.

@weaverryan
Copy link
Member

Hi guys!

I certainly don't mind the addition of the new features here, but I'm -1 on the BC breaks and deprecations. I don't love the deprecation ofform_enctype, and I wish theform_start andform_end things would have come earlier, as we'll have a mixture on the web (think 2.0 + 2.1 versus 2.2+ docs, blog posts, etc) of things usingform_enctype andform_rest versusform_start andform_end. Individually, I like the feature, but I'm not sure having this big change is worth it.

Also, I really really don't like the deprecation ofform->bind - this will affect far too many projects and the newform->process is just a "nice" feature, at the cost of so much BC breaking. Again, I'm not sure getting rid of the current way is worth it, but I'm also not sure that having bothform->bind andform->process is clear either.

Overall, I'd like to see these "nice" things added in a way where they can co-exist with what we have currently. These are really nice features, but there's so much code that will need to update and "education" that will need to happen because the form framework is already being used in so many places.

Thanks!

@webmozart
Copy link
ContributorAuthor

@weaverryan For reference, this PR does not contain any (immediate) BC breaks, just deprecations.

We can leave inform_enctype without too much hassle if you feel that this is a problem. It is just not necessary anymore. We can also postpone the version where we remove this feature.

$form->bind($request) was not only deprecated for cleanup purposes, but also for performance reasons. Currently,BindRequestListener is attached to and invoked for each and every form element. Upgrading this is very easy so I don't really see the necessity for leaving this in. Again, we can postpone the removal date here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Again, this looks like the allowed methods can be changed, like adding or removing some. But that's not the case.
Why not simply inline the allowed methods insetMethod?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think I explained this sufficiently above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

No, I don't see any valid reason against:

if (!in_array($upperCaseMethod, array('GET', 'PUT', 'POST', 'DELETE', 'PATCH'))) {    throw new FormException(sprintf(        'The form method is "%s", but should be one of "GET", "PUT", "POST", "DELETE", "PATCH".',        $method    ));}

@jalliot
Copy link
Contributor

What is the point of theform_end helper if it only renders a</form> tag?
If it was implemented by a customizable block or if it rendered alsoform_rest then why not but in the current state it seems really overkill.

@webmozart
Copy link
ContributorAuthor

@jalliotform_end does also renderform_rest

@jalliot
Copy link
Contributor

@bschussek Oh right sorry... I did not refresh my page and did not see the new commits.

@michelsalib
Copy link

Really nice work @bschussek. I like the way the form component is taking. There is still a lot of work, but hey, forms are a complex thing.
So it is a big 👍 for me.

@webmozart
Copy link
ContributorAuthor

Postponed to 2.3

@webmozart
Copy link
ContributorAuthor

Reviewed again and rebased on master.

@webmozart
Copy link
ContributorAuthor

Again, the test failures on 5.3 seem unrelated to this PR. Reviewed and updated the documentation.

@stof
Copy link
Member

@bschussek the fix for 5.3 has just been merged

@webmozart
Copy link
ContributorAuthor

Rebased again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

IIRC when something will be removed in3.0, it should not throw error, right@fabpot ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

You are right. We will trigger the error just before 3.0. For now, it should only be documented in the CHANGELOG for 3.0.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Fixed

@mvrhov
Copy link

I'm guessing that this still won't handle the case where you have the data for two forms present e.g. the http method is something different that GET, but the query part of the uri contains the data submitted in a search in a previous step. Right now you need to know the form name and get such a data from the request and then bind manually.... This becomes annoying and tedious if you need to persist this through more than one step...

fabpot added a commit that referenced this pull requestApr 19, 2013
This PR was merged into the master branch.Discussion----------[2.3] [Form] Implemented form processorsBug fix: noFeature addition: yesBackwards compatibility break: noSymfony2 tests pass: yesFixes the following tickets: partially#5493Todo: -License of the code: MITDocumentation PR:symfony/symfony-docs#2092Commits-------11fee06 [TwigBridge] Removed duplicate entries from the CHANGELOG68f360c [Form] Moved upgrade nodes to UPGRADE-3.001b71a4 [Form] Removed trigger_error() for deprecations as of 3.081f8c67 [Form] Implemented form processors0ea75db [Form] Improved FormRenderer::renderBlock() to be usable outside of form blocks
@fabpotfabpot merged commit11fee06 intosymfony:masterApr 19, 2013
@stof
Copy link
Member

@mvrhov the Form component is able to get the right data based on its name (since 2.0)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Well, submit buttons do support actions via "formaction" attribute. Also methods with "formmethod".

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good point. Could you open a ticket please?

@mvrhov
Copy link

@stof
Imagine the two step wizard. The first step is a search form ($form1) with action set to GET.
Now the second step contains another form ($form2) with action set to POST and the query parameters from the$form1 are part of action uri for$form2.

However in the action that gets executed on second step you need data from both form1 and form2 to complete the action. So calling$form2->bind($request), only the $from2 will get bound.
If you also want to bind the data to$form1 then you have to do..$form->bind($request->query->get('form_name'));

@webmozart
Copy link
ContributorAuthor

@mvrhov IMO this is the wrong approach to the problem. You should not bind data that you already successfully submitted again. Instead, store the values somewhere in your session and write them into your persistence layer when you're done with the wizard.

@stof
Copy link
Member

@mvrhov if you want to bind$form, call$form->bind($request) too. There is no reason for$form2->bind() to bind$form (it does not even know that you have a second Form instance created in your code)

fabpot added a commit that referenced this pull requestApr 23, 2013
This PR was merged into the master branch.Discussion----------[Form] Deprecated bind() and isBound() in favor of submit() and isSubmitted()| Q             | A| ------------- | ---| Bug fix?      | no| New feature?  | no| BC breaks?    | yes (*)| Deprecations? | yes| Tests pass?   | yes| Fixed tickets |#5493| License       | MIT| Doc PR        | TODOThis change was discussed for a while in#5493. **(*)** It breaks BC *only for people who implemented* `FormInterface` *manually* (not a lot, so I hope). These can fix the problem by simply renaming `bind()` and `isBound()` in their implementation to `submit()` and `isSubmitted()`.The main rationale is that with the request handlers introduced in#6522, people won't be confronted with the term "binding" anymore. As such, `isBound()` will be a very strange name to new users that have never used `bind()` manually.See this code sample as example:```php$form = $this->createForm(...);$form->handleRequest($request);// Imagine you have never heard about bind() or binding. What does this mean?if ($form->isBound()) {    // ...}```In reality, `bind()` submits a form. Where-ever I renamed "bind" to "submit" in the comments, "submit" made actually much more sense. So it does in the code sample above:```php$form = $this->createForm(...);$form->handleRequest($request);// Aha!if ($form->isSubmitted()) {    // ...}```Also when using `submit()` directly, the code makes much more sense now:```php$text = $this->createForm('text');$text->submit('New Value');```For current users, the current naming will be supported until 3.0.Commits-------41b0127 [Form] Deprecated bind() and isBound() in favor of submit() and isSubmitted()
weaverryan added a commit to symfony/symfony-docs that referenced this pull requestOct 19, 2014
….3 (xabbuh)This PR was merged into the 2.3 branch.Discussion----------[Component][Forms] add missing features introduced in 2.3| Q             | A| ------------- | ---| Doc fix?      | no| New docs?     | yes (symfony/symfony#6522)| Applies to    | all| Fixed tickets |#2969- [x] use ``submit()`` instead of ``bind()`` to manually submit a form- [x] configure method and action of a form- [ ] ~~render a form's start and its end separately~~ (see [the comment](#4085 (comment)))- [ ] configure buttonsCommits-------33f6422 [Forms] add missing features being new in 2.3
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

11 participants

@webmozart@Tobion@weaverryan@jalliot@michelsalib@stof@mvrhov@andreia@fabpot@stloyd@vicb

[8]ページ先頭

©2009-2025 Movatter.jp