From 998742f3e039b3d70d67cf944a60646ecb073f88 Mon Sep 17 00:00:00 2001 From: Rogerio Prado de Jesus Date: Mon, 20 Feb 2012 19:24:58 -0200 Subject: [PATCH 1/2] [pt_BR][jobeet][day10] Include english version --- jobeet/pt_BR/10.markdown | 1053 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 1053 insertions(+) create mode 100644 jobeet/pt_BR/10.markdown diff --git a/jobeet/pt_BR/10.markdown b/jobeet/pt_BR/10.markdown new file mode 100644 index 0000000..15bd954 --- /dev/null +++ b/jobeet/pt_BR/10.markdown @@ -0,0 +1,1053 @@ +Day 10: The Forms +================= + +Previous day of this Jobeet tutorial got off to a flying start with the +introduction of the symfony test framework. We will continue today with the form +framework. + +The Form Framework +------------------ + +Any website has ~forms|Forms~; from the simple contact form to the complex ones +with lots of fields. Writing forms is also one of the most complex and tedious +task for a web developer: you need to write the HTML form, implement validation +rules for each field, process the values to store them in a database, display +error messages, repopulate fields in case of errors, and much more... + +Of course, instead of reinventing the wheel over and over again, symfony +provides a framework to ease form management. The form framework is made of +three parts: + + * **validation**: The ~validation|Validation~ sub-framework provides classes + to validate inputs (integer, string, email address, ...) + + * **widgets**: The ~widget|Widgets~ sub-framework provides classes to + output HTML fields (input, textarea, select, ...) + + * **forms**: The ~form|Forms~ classes represent forms made of widgets and + validators and provide methods to help manage the form. + Each form field has its own validator and widget. + +Forms +----- + +A symfony form is a class made of fields. Each field has a name, a +~validator|Validators~, and a ~widget|Widgets~. A simple `ContactForm` can be +defined with the following class: + + [php] + class ContactForm extends sfForm + { + public function configure() + { + $this->setWidgets(array( + 'email' => new sfWidgetFormInputText(), + 'message' => new sfWidgetFormTextarea(), + )); + + $this->setValidators(array( + 'email' => new sfValidatorEmail(), + 'message' => new sfValidatorString(array('max_length' => 255)), + )); + } + } + +Form fields are configured in the `configure()` method, by using the +`setValidators()` and `setWidgets()` methods. + +>**TIP** +>The form framework comes bundled with a lot of +>[widgets](http://www.symfony-project.org/api/1_4/widget) and +>[validators](http://www.symfony-project.org/api/1_4/validator). The API +>describes them quite extensively with all the options, errors, and default +>error messages. + +The widget and validator class names are quite explicit: the `email` field will +be rendered as an HTML `` tag (`sfWidgetFormInputText`) and validated as +an email address (`sfValidatorEmail`). The `message` field will be rendered as a +`