Skip to content

[Form] Simplify request handling #5493

@webmozart

Description

@webmozart

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?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy