0

I have a code-validator form, built out of the model. The user select a product from a predefined list (loaded from an entity), and enters his unique code to validate it. This is:

class CodeType extends AbstractType {
  public function buildForm(FormBuilder $builder, array $options) {
    $builder->add('product', 'entity', array(
                'class' => 'CapsaClubCommonBundle:ProductSubFormat',
                'query_builder' => function(EntityRepository $er) {
                    return $er->createQueryBuilder('p')
                            ->where('p.active=1')
                            ->orderBy('p.id', 'ASC');
                },
                'property' => 'description',
                'required' => true,
                'label' => 'Select a product',
                'property_path' => false
            ))
        ->add('code', 'text', array(
              'property_path' => false));
  }
  public function getName() {
    return 'enter_code';
  }
}

The problem is that I need to add the choice if user wants to validate more than one code at once, so I ended up adding this (following this guide):

class CollectionCodeType extends AbstractType {
public function buildForm(FormBuilder $builder, array $options) {
    $builder->add('codes', 'collection', array(
                'type' => new CodeType(), 
                'allow_add' => true,
                'prototype' => true,
                'by_reference' => false,
                'property_path' => false
                ));
  }
  public function getName() {
    return 'collection_code';
  }

}

And then calling it in the controller $form = $this->createForm(new CollectionCodeType());, but is not working. No errors, simply it doesn't show the form.

I don't know how this should be done, because I am not sure if building out of the model is correct, but in this case I think there is no other way to achieve what I need.

Many thanks.

EDIT: Rendering the form: http://pastebin.com/aSrUx67N

4

0 回答 0