Symfony formlarda uygulama Fieldset

0 Cevap php

on the project I am writing with Symfony, there will be fieldsets in forms very often, so I would like to create a mechanism so that I can group fields by fieldsets and still use the __toString() method of my forms. On this page, I read about the sfWidgetFormSchema, and how it could be considered as a widget, which enables to nest fields. So here is what I did: I created nested fields:

   $this->setWidgets(array(
      'customer'    => new sfWidgetFormSchema(array(
        'customer_name'      => new sfWidgetFormInputText(),
        'customer_email'     => new sfWidgetFormInputText(array())
      )),
      'library'     => new sfWidgetFormSchema(array(
        'library_name'      => new sfWidgetFormInputText(),
        'library_address'   => new sfWidgetFormInputText(),
        'library_city'      => new sfWidgetFormInputText(),
        'library_postcode'  => new sfWidgetFormInputText(),
        'library_website'   => new sfWidgetFormInputText()
      )),
      'message'     => new sfWidgetFormTextarea(array(),array( "cols" => 50, "rows" => 10 )),
    ));

Sonra temelde etiketleri alanları saran bir fieldsetFormSchemaFormatter sınıf oluşturulur ve sfWidgetFormSchema alanları ile ilişkili:

foreach (array('customer', 'library') as $fieldset)
    {
      $this->widgetSchema[$fieldset]->addFormFormatter('tableless',
        new tableLessFormSchemaFormatter($this->widgetSchema['customer']));
      $this->widgetSchema[$fieldset]->setFormFormatterName('tableless');
      $this->widgetSchema[$fieldset]->setNameFormat('%s');
    }
    $this->widgetSchema->addFormFormatter('fieldset',
      new FieldsetFormSchemaFormatter($this->widgetSchema,
        'TableLessFormSchemaFormatter'));
    $this->widgetSchema->setFormFormatterName('fieldset');

And it just worked fine, I got my fieldset form. The problem I have is with validation, which is not at all described on the page I linked sooner in this question. The error messages appear on top of the form for all fields but the "message" field, which has an error message right after it. I don't think I'm gonna be able to get the error messages to display right after the rows and still use the echo $form construct without coding something ugly, so I think I'm gonna go with another implementation. I think that sfWidgetFormSchema widgets are meant to build interdependant fields, which would have global validation rules.

Nasıl bu fieldset işlevi uygulamak istiyorsunuz?

0 Cevap