-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
} | ||
|
||
$name = $form->getName(); | ||
$method = $form->getConfig()->getMethod(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved after if
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean line above 😮
There was a problem hiding this comment.
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.
Added the helpers |
After: | ||
|
||
``` | ||
if ($form->process($request)->isValid()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example in Before
and After
will probably confuse people that use the else
part of the condition. So it should make clear that one must check isBound
before falsely adding flash messages about an invalid form (that is not even bound).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
We discussed in #5493 whether
or
What do you think? |
Another question that remains to be answered: With the current implementation, the attributes passed in the
Solutions that come to mind: (a) Move the rendering of the attributes from the
(b) Don't render a
(c) Don't render any attributes in the
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 (a) and (b), on the other hand, break BC for those people that use |
Added the helper
|
} else { | ||
$default = $form->getConfig()->getCompound() ? array() : null; | ||
$data = isset($_POST[$name]) ? $_POST[$name] : $default; | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 from FileBag
for that.
@bschussek I think And to the question about attributes: I think we should not maintain BC here with c) because attributes are better applied to the parent. Using CSS you can easily select the child with |
{% spaceless %} | ||
{{ form_start(form) }} | ||
{{ form_widget(form) }} | ||
<input type="submit" /> |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@Tobion This is not correct. With (b), each row would still be wrapped in a |
*/ | ||
interface FormProcessorInterface | ||
{ | ||
public function processForm(FormInterface $form, $request = null); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed
I propose to postpone the question about the wrapping @fabpot This PR should be mergeable. |
Updated the documentation. |
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 of Also, I really really don't like the deprecation of 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! |
@weaverryan For reference, this PR does not contain any (immediate) BC breaks, just deprecations. We can leave in
|
* | ||
* @var array | ||
*/ | ||
private static $allowedMethods = array( |
There was a problem hiding this comment.
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 in setMethod
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
));
}
What is the point of the |
@jalliot |
@bschussek Oh right sorry... I did not refresh my page and did not see the new commits. |
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. |
Postponed to 2.3 |
Reviewed again and rebased on master. |
Again, the test failures on 5.3 seem unrelated to this PR. Reviewed and updated the documentation. |
@bschussek the fix for 5.3 has just been merged |
Rebased again. |
parent::compile($compiler); | ||
|
||
$compiler->raw(";\n"); | ||
$compiler->write('trigger_error(\'The helper form_enctype(form) is deprecated since version 2.3 and will be removed in 3.0. Use form_start(form) instead.\', E_USER_DEPRECATED)'); |
There was a problem hiding this comment.
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 in 3.0
, it should not throw error, right @fabpot ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
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... |
This PR was merged into the master branch. Discussion ---------- [2.3] [Form] Implemented form processors 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 Commits ------- 11fee06 [TwigBridge] Removed duplicate entries from the CHANGELOG 68f360c [Form] Moved upgrade nodes to UPGRADE-3.0 01b71a4 [Form] Removed trigger_error() for deprecations as of 3.0 81f8c67 [Form] Implemented form processors 0ea75db [Form] Improved FormRenderer::renderBlock() to be usable outside of form blocks
@mvrhov the Form component is able to get the right data based on its name (since 2.0) |
*/ | ||
public function setAction($action) | ||
{ | ||
throw new \BadMethodCallException('Buttons do not support actions.'); |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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?
@stof However in the action that gets executed on second step you need data from both form1 and form2 to complete the action. So calling |
@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. |
@mvrhov if you want to bind |
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 | TODO This 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()
….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 buttons Commits ------- 33f6422 [Forms] add missing features being new in 2.3
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