-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Closed
Description
We could simplify the form request handling by
- supporting a "method" option
- supporting a "request" option that binds the request if its method matches "method"
- supporting an "action" option and helpers for opening and closing tags
We previously had this idea and dropped it. I was inspired again by Zend Framework 2's API and thought that it might be a good idea. Kudos to them.
Proposed simplification (fully BC):
<?php
// in the controller
$form = $this->createForm('my_form', null, array(
'action' => $this->generateUrl('process_form'),
'method' => 'POST',
'request' => $request,
));
// Alternative 1: short
if ($form->isValid()) {
// process form
}
// Alternative 2: self-describing
if ($form->isBound() && $form->isValid()) {
// process form
}
Note that the check for $request->getMethod()
is not necessary anymore in the above snippet. Also, bind($request)
is done implicitely by passing the "request" option (explicit binding is also possible, of course).
{# in the template #}
{{ form_start(form) }}
{{ form_widget(form) }}
<input type="submit" />
{{ form_end(form) }}
{# alternative with explicit method or action #}
{{ form_start(form, { method: "GET" }) }}
Thoughts? Preferences for Alternative 1 or 2?