Skip to content

Instantly share code, notes, and snippets.

@bchoquet-heliopsis
Last active August 29, 2015 13:56
Show Gist options
  • Save bchoquet-heliopsis/9113340 to your computer and use it in GitHub Desktop.
Save bchoquet-heliopsis/9113340 to your computer and use it in GitHub Desktop.
<?php
//src/Acme/FormBundle/Forms/CustomFormType.php
namespace Acme\FormBundle\Forms;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Acme\FormBundle\Entity\FormData;
class CustomFormType extends AbstractType
{
public function getName()
{
return 'acme_custom_form';
}
public function buildForm( FormBuilderInterface $builder, array $options )
{
$builder->add( 'field1', 'text', array( 'required' => true, 'label' => 'My Custom Field' );
$builder->add( 'field2', 'choice', array( 'label' => 'My Custom Select', 'choices' => array( 1, 2, 3 ) );
$builder->add( 'submit', 'submit', array( 'label' => 'Go!' );
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults( array(
'data_class' => 'Acme\FormBundle\Entity\FormData'
) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment