Book Image

Extending Symfony2 Web Application Framework

By : Sebastien Armand
Book Image

Extending Symfony2 Web Application Framework

By: Sebastien Armand

Overview of this book

Table of Contents (13 chapters)

Going further


For the last part of this chapter, we will go a bit further with the customization of forms.

A part of our meetups website requires a user to enter their house address so that they can receive a membership card that will be directly sent out to them. Since we already have a relatively good idea where that user is coming from, we will preset the country for them in the form. Here, we only differentiate between users coming from within or outside the USA to decide if they must fill in the state they are coming from.

The initial setup

Our Address class is very simple and contains only a few attributes as well as getters and setters, as shown in the following code snippet:

class Address
{
    protected $id;

    protected $street;

    protected $number;

    protected $country;

    protected $state;

    protected $zip;

    // public function getXxx();
    // public function setXxx($x);
}

The basic form class will be as shown in the following code:

class AddressType extends AbstractType...