-
-
Save webmozart/7597726 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\Form\Forms; | |
use Symfony\Component\Form\AbstractType; | |
use Symfony\Component\Form\FormBuilderInterface; | |
use Symfony\Component\Form\FormEvent; | |
use Symfony\Component\Form\FormEvents; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
class ApplicationFormType extends AbstractType | |
{ | |
public function buildForm(FormBuilderInterface $builder, array $options) | |
{ | |
$builder->add('title', 'text', array( | |
'label' => 'Application title', | |
)); | |
$builder->add('description', 'text', array( | |
'label' => 'Application description', | |
)); | |
$builder->setData(array( | |
'title' => 'A default title', | |
'description' => 'A default description', | |
)); | |
$builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) use (&$defaultData) { | |
$defaultData = $event->getForm()->getData(); | |
var_dump($defaultData); | |
}, 255); | |
} | |
public function getName() | |
{ | |
return 'application'; | |
} | |
} | |
$factory = Forms::createFormFactoryBuilder()->getFormFactory(); | |
$form = $factory->create(new ApplicationFormType()); | |
$form->submit(array()); | |
// expecting array('title' => 'A defaut title', 'description' => 'A defaut description') but got null | |
var_dump($form->getData()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment