12.07.2015 Views

A Gentle Introduction to symfony (pdf) - Bad Request

A Gentle Introduction to symfony (pdf) - Bad Request

A Gentle Introduction to symfony (pdf) - Bad Request

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 10: Forms 159Chapter 10FormsDealing with the display of form inputs, the validation of a form submission, and all theparticular cases of forms is one of the most complex tasks in web development. Luckily,<strong>symfony</strong> provides a simple interface <strong>to</strong> a very powerful form sub-framework, and helps you <strong>to</strong>design and handle forms of any level of complexity in just a few lines of code.Displaying a FormA simple contact form featuring a name, an email, a subject and a message fields typicallyrenders as follows:In <strong>symfony</strong>, a form is an object defined in the action and passed <strong>to</strong> the template. In order <strong>to</strong>display a form, you must first define the fields it contains - <strong>symfony</strong> uses the term “widget”.The simplest way <strong>to</strong> do it is <strong>to</strong> create a new sfForm object in the action method.// in modules/foo/actions/actions.class.phppublic function executeContact($request){$this->form = new sfForm();$this->form->setWidgets(array('name' => new sfWidgetFormInputText(),Listing10-1----------------- Brought <strong>to</strong> you by

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!