1. Castelln - 5 y 6 de Julio 2010 Universitat Jaume I organizan
patrocinan colaboran Jornadas Symfony 5 y 6 de julio 2010
Universitat Jaume I, Castelln http://decharlas.uji.es/symfony
3. Jornadas Symfony 5 y 6 de julio 2010 Universitat Jaume I,
Castelln http://decharlas.uji.es/symfony Domesticando los
formularios: sfForm Jose Antonio Pio Acilia.es
4. Jornadas Symfony http://decharlas.uji.es/symfony Presentacin
CTO Acilia Internet Madrid Jornadas Symfony
http://decharlas.uji.es/symfony Background + Estudie Ingeniera
Electrnica + Empece a trabajar con internet en el 2001... y aqu
sigo. + PHP y Ruby + CakePHP, Rails, CodeIgniter y Symfony 1.2 -
1.4
8. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Contenido + Formularios el
SubFramework + Las Clases + Formularios + Widgets + Validators +
Funcionalidades y clases
9. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Domestiquemos los
Formularios Cmo se hace un embedded form?
10. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony EmbeddedForm As se hace
public function configure() { . .. $this ->embedForm(
'newPhotos' , new ObjectForm( $ObjectRelated ) ); }
11. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony EmbeddedForm Para esto lo
he usado class UserAdminForm extends BasesfGuardUserAdminForm {
public function configure() { . .. $profileForm = new
sfGuardUserProfileForm( $this ->object->profile); $this
->embedForm( "profile" , $profileForm ); } }
12. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Symfony Forms
SubFrameWork
18. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Formularios Ejemplo
Formulario de Contacto public function executeContact( $request ) {
$this ->form = new sfForm(); $this ->form->setWidgets(
array ( 'name' => new sfWidgetFormInputText(), 'message' =>
new sfWidgetFormTextarea(), )); $this ->form->setValidators(
array ( 'name' => new sfValidatorString( array ( 'max_length'
=> 10 ) ), 'message' => new sfValidatorString( array (
'max_length' => 20 )) )); $this
->form->getWidgetSchema()->setNameFormat( 'contact[%s]' );
// Deal with the request if ( $request ->isMethod( 'post' )){
$this ->form->bind( $request ->getParameter( $this
->form->getName()) ); if ( $this ->form->isValid() ){
var_export ( $this ->form->getValues() ); } $this
->redirect( "module/contact" ); } }
19. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Formularios Ejemplo
Formulario de Contacto public function executeContact($request) {
$this ->form = new sfForm();
$this->form->setWidgets(array( 'name' => new
sfWidgetFormInputText(), 'message' => new
sfWidgetFormTextarea(), )); $this->form->setValidators(array(
'name' => new sfValidatorString( array ( 'max_length' => 10 )
), 'message' => new sfValidatorString( array ( 'max_length'
=> 20 )) ));
$this->form->getWidgetSchema()->setNameFormat('contact[%s]');
// Deal with the request if ($request->isMethod('post')){
$this->form->bind(
$request->getParameter($this->form->getName()) ); if (
$this->form->isValid() ){ var_export (
$this->form->getValues() ); }
$this->redirect("module/contact"); } }
20. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Formularios Ejemplo
Formulario de Contacto public function executeContact($request) {
$this->form = new sfForm(); $this ->form->setWidgets(
array ( 'name' => new sfWidgetFormInputText(), 'message' =>
new sfWidgetFormTextarea(), ));
$this->form->setValidators(array( 'name' => new
sfValidatorString( array ( 'max_length' => 10 ) ), 'message'
=> new sfValidatorString( array ( 'max_length' => 20 )) ));
$this->form->getWidgetSchema()->setNameFormat('contact[%s]');
// Deal with the request if ($request->isMethod('post')){
$this->form->bind(
$request->getParameter($this->form->getName()) ); if (
$this->form->isValid() ){ var_export (
$this->form->getValues() ); }
$this->redirect("module/contact"); } }
21. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Formularios Ejemplo
Formulario de Contacto public function executeContact($request) {
$this->form = new sfForm(); $this->form->setWidgets(array(
'name' => new sfWidgetFormInputText(), 'message' => new
sfWidgetFormTextarea(), )); $this ->form->setValidators(
array ( 'name' => new sfValidatorString( array ( 'max_length'
=> 10 ) ), 'message' => new sfValidatorString( array (
'max_length' => 20 )) )); // Error extra Form Field si no hay
validador ->isValid
$this->form->getWidgetSchema()->setNameFormat('contact[%s]');
// Deal with the request if ($request->isMethod('post')){
$this->form->bind(
$request->getParameter($this->form->getName()) ); if (
$this->form->isValid() ){ var_export (
$this->form->getValues() ); }
$this->redirect("module/contact"); } }
22. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Formularios Ejemplo
Formulario de Contacto public function executeContact($request) {
$this->form = new sfForm(); $this->form->setWidgets(array(
'name' => new sfWidgetFormInputText(), 'message' => new
sfWidgetFormTextarea(), )); $this->form->setValidators(array(
'name' => new sfValidatorString( array ( 'max_length' => 10 )
), 'message' => new sfValidatorString( array ( 'max_length'
=> 20 )) )); $this
->form->getWidgetSchema()->setNameFormat( 'contact[%s]' );
// Deal with the request if ($request->isMethod('post')){
$this->form->bind(
$request->getParameter($this->form->getName()) ); if (
$this->form->isValid() ){ var_export (
$this->form->getValues() ); }
$this->redirect("module/contact"); } }
23. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Formularios Ejemplo
Formulario de Contacto public function executeContact($request) {
$this->form = new sfForm(); $this->form->setWidgets(array(
'name' => new sfWidgetFormInputText(), 'message' => new
sfWidgetFormTextarea(), )); $this->form->setValidators(array(
'name' => new sfValidatorString( array ( 'max_length' => 10 )
), 'message' => new sfValidatorString( array ( 'max_length'
=> 20 )) ));
$this->form->getWidgetSchema()->setNameFormat('contact[%s]');
// Deal with the request if ( $request ->isMethod( 'post' )){
$this ->form->bind( $request ->getParameter( $this
->form->getName()) ); if ( $this ->form->isValid() ){
var_export ( $this ->form->getValues() ); }
$this->redirect("module/contact"); } }
24. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Formularios Ejemplo
Formulario de Contacto public function executeContact($request) {
$this->form = new sfForm(); $this->form->setWidgets(array(
'name' => new sfWidgetFormInputText(), 'message' => new
sfWidgetFormTextarea(), )); $this->form->setValidators(array(
'name' => new sfValidatorString( array ( 'max_length' => 10 )
), 'message' => new sfValidatorString( array ( 'max_length'
=> 20 )) ));
$this->form->getWidgetSchema()->setNameFormat('contact[%s]');
// Deal with the request if ($request->isMethod('post')){
$this->form->bind(
$request->getParameter($this->form->getName()) ); if (
$this->form->isValid() ){ var_export (
$this->form->getValues() ); } $this ->redirect(
"module/contact" ); } }
26. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Formularios Vista del
Formulario de Contacto < table > < tr > < td colspan
= "2" > < input type = "submit" /> td > tr > table
> form > < ul > < li > < li > < input
type = "submit" / d > li > ul > form >
27. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Formularios Manipulando los
campos del formulario < ul > < li > < div class =
"error" > div > li > < li > < input type =
"submit" /> li > ul > form >
30. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony sfForm sfForm. class .php
sfFormField. class .php sfFormFieldSchema. class .php sfFormFilter.
class .php sfFormObject. class .php sfFormSymfony. class .php
sfFormFieldSchema sfFormField sfForm ArrayAccess Countable Iterator
Clases Relativas a los Formularios
31. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony sfForm Clases Relativas a
los Formularios sfForm ArrayAccess Countable Iterator sfFormSymfony
BaseForm sfFormObject
54. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Validators Mas sobre el
proceso de Validacin $form->bind( $values, $fliles );
sfForm::doBind($values);
$this->$this->validatorSchema->clean($values)
sfValidatorSchema::clean($values); $this->doClean($values);
$this->preClean($values); foreach ($values as $name =>
$value) $clean[$name] = $this->fields[$name]->clean($value);
$clean = $this->postClean($clean); return $clean;
55. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Validators Mas sobre el
proceso de Validacin $form->bind( $values, $fliles );
sfForm::doBind($values);
$this->$this->validatorSchema->clean($values)
sfValidatorSchema::clean($values); $this->doClean($values);
$this->preClean($values); foreach ($values as $name =>
$value) $clean[$name] = $this->fields[$name]->clean($value);
$clean = $this->postClean($clean); return $clean;
56. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Validators Mas sobre el
proceso de Validacin $form->bind( $values, $fliles );
sfForm::doBind($values);
$this->$this->validatorSchema->clean($values)
sfValidatorSchema::clean($values); $this->doClean($values);
$this->preClean($values); foreach ($values as $name =>
$value) $clean[$name] = $this->fields[$name]->clean($value);
$clean = $this->postClean($clean); return $clean;
57. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Validators Mas sobre el
proceso de Validacin $form->bind( $values, $fliles );
sfForm::doBind($values);
$this->$this->validatorSchema->clean($values)
sfValidatorSchema::clean($values); $this->doClean($values);
$this->preClean($values); foreach ($values as $name =>
$value) $clean[$name] = $this->fields[$name]->clean($value);
$clean = $this->postClean($clean); return $clean;
58. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Validators Mas sobre el
proceso de Validacin $this ->form->bind( $request
->getParameter( $this ->form->getName()) ); public
function bind( array $taintedValues = null, array $taintedFiles =
null){ . .. try { $this ->doBind( self ::deepArrayUnion( $this
->taintedValues, self ::convertFileInformation( $this
->taintedFiles))); . .. } ... } protected function doBind( array
$values ){ $this ->values = $this
->validatorSchema->clean( $values ); }
59. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Funcionalidades y
Clases
60. Jornadas Symfony http://decharlas.uji.es/symfony Jornadas
Symfony http://decharlas.uji.es/symfony Guardando los Formularios
de Objetos Save y doSave