You can manipulate the widget and validator schemas as if they were 
arrays... except they are not. Instead of creating an array, you need to 
create a sfWidgetSchema, which behaves like an array.

So, in your case, you have 2 options:

   * Create a form for your collection of widgets and embed it: symfony 
will do the ground work for you
   * Do everything by hand

Here is an example for the first option:

<?php

class ThingForm extends sfForm
{
   public function configure()
   {
     // ...

     $this->embedForm('group', new checkboxesCollectionForm());
   }
}

class checkboxesCollectionForm extends sfForm
{
   public function configure()
   {
     foreach (array('foo', 'bar') as $value)
     {
       $this->widgetSchema[$value] = new sfWidgetFormInputCheckbox();
       $this->validatorSchema[$value] = new sfValidatorPass();
     }
   }
}

I've attached a screenshot for this example.

And here is the exact same example but you do everything by yourself:

<?php

class ThingForm extends sfForm
{
   public function configure()
   {
     // ...

     $this->widgetSchema['group'] = new sfWidgetFormSchema();
     $this->validatorSchema['group'] = new sfValidatorSchema();
     foreach (array('foo', 'bar') as $value)
     {
       $this->widgetSchema['group'][$value] = new 
sfWidgetFormInputCheckbox();
       $this->validatorSchema['group'][$value] = new sfValidatorPass();
     }
   }
}

If you want to use the <?php echo $form ?> statement, you will have to 
decorate the collection like this:

$this->widgetSchema['group'] = new 
sfWidgetFormSchemaDecorator($this->widgetSchema['group'], 
$this->widgetSchema['group']->getFormFormatter()->getDecoratorFormat());

Fabien

Ian wrote:
> One additional note.  It's often common to have one "label" for the
> entire collection of checkboxes.  So i'd like to be able to do this as
> well.
> 
> On Jun 2, 5:16 pm, "Slick Rick" <[EMAIL PROTECTED]> wrote:
>> I'm trying to create a dynamic list of "groups", that can be selected via 
>> checkboxes.  What is the best way to create this "collection" of checkbox 
>> widgets in my form class so it is handled by the rendering engine as well as 
>> validation and error handling?
>>
>> I tried to do this:
>>
>> foreach ($groups as $group)
>> {
>>   $schema['group'][] = new sfWidgetFormInputCheckbox(array(), array('value' 
>> => $group['id']));
>>
>> }
>>
>> ... but when I try to render it, it tells me Widget "group" does not exist.  
>> Even if try to echo $form['group'][0]->render().  Same error.
>>
>> Is there some internal mechanism that can handle groups of form elements 
>> properly?
>>
>> Thanks for any help...
>>
>> -- Ian
> > 

-- 
Fabien Potencier
Sensio CEO - symfony lead developer
sensiolabs.com | symfony-project.com | aide-de-camp.org
Tél: +33 1 40 99 80 80

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---

<<inline: form.png>>

Reply via email to