Skip to content

Form doc fix #95

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
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions guides/forms/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ method ``configure()`` to initialize the form with a set of fields.
.. code-block:: php

// src/Sensio/HelloBundle/Contact/ContactForm.php
use Symfony\Component\Form
use Symfony\Component\Form\TextField
use Symfony\Component\Form\TextareaField
use Symfony\Component\Form\EmailField
use Symfony\Component\Form\CheckboxField
namespace Sensio\HelloBundle\Contact;

use Symfony\Component\Form\Form;
use Symfony\Component\Form\TextField;
use Symfony\Component\Form\TextareaField;
use Symfony\Component\Form\CheckboxField;

class ContactForm extends Form
{
Expand All @@ -64,7 +65,7 @@ method ``configure()`` to initialize the form with a set of fields.
'max_length' => 100,
)));
$this->add(new TextareaField('message'));
$this->add(new EmailField('sender'));
$this->add(new TextField('sender'));
$this->add(new CheckboxField('ccmyself', array(
'required' => false,
)));
Expand All @@ -73,7 +74,7 @@ method ``configure()`` to initialize the form with a set of fields.

A form consists of ``Field`` objects. In this case, our form has the fields
``subject``, ``message``, ``sender`` and ``ccmyself``. ``TextField``,
``TextareaField``, ``EmailField`` and ``CheckboxField`` are only four of the
``TextareaField`` and ``CheckboxField`` are only three of the
available form fields; a full list can be found in :doc:`Form fields
<fields>`.

Expand All @@ -87,8 +88,8 @@ The standard pattern for using a form in a controller looks like this:
// src/Sensio/HelloBundle/Controller/HelloController.php
public function contactAction()
{
$contactRequest = new ContactRequest();
$form = ContactForm::create($this->get('form.context'));
$contactRequest = new ContactRequest( $this->get( 'mailer' ) );
$form = ContactForm::create($this->get('form.context'), 'contact');

// If a POST request, write submitted data into $contactRequest
// and validate it
Expand Down Expand Up @@ -122,8 +123,8 @@ and settings that a form needs to work.

.. code-block:: php

use Symfony\Component\Form\FormContext
use Symfony\Component\HttpFoundation\Request
use Symfony\Component\Form\FormContext;
use Symfony\Component\HttpFoundation\Request;

$context = FormContext::buildDefault();
$request = Request::createFromGlobals();
Expand All @@ -139,6 +140,8 @@ class could look like this:
.. code-block:: php

// src/Sensio/HelloBundle/Contact/ContactRequest.php
namespace Sensio\HelloBundle\Contact;

class ContactRequest
{
protected $subject = 'Subject...';
Expand Down Expand Up @@ -204,6 +207,8 @@ data.
.. code-block:: php

// src/Sensio/HelloBundle/Contact/ContactRequest.php
namespace Sensio\HelloBundle\Contact;

class ContactRequest
{
/**
Expand Down Expand Up @@ -318,6 +323,7 @@ can do so by using the other built-in form rendering helpers.
# src/Sensio/HelloBundle/Resources/views/Hello/contact.html.twig
{% extends 'HelloBundle::layout.html.twig' %}

{% block content %}
<form action="#" method="post" {{ form_enctype(form) }}>
{{ form_errors(form) }}

Expand All @@ -332,6 +338,7 @@ can do so by using the other built-in form rendering helpers.
{{ form_hidden(form) }}
<input type="submit" />
</form>
{% endblock %}

Symfony2 comes with the following helpers:

Expand Down