I have the following silex code to present a simple form and message upon completion:
$app->register(new Silex\Provider\FormServiceProvider\FormServiceProvider());
$app->register(new Silex\Provider\ValidatorServiceProvider());
$app->match('/contact', function(Request $request) use ($app) {
$form = $app['form.factory']->createBuilder('form', null)
->add('name', 'text', array('required' => true, 'label' => 'Name',))
->add('submit', 'submit')
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
die('success);
}
return $app['twig']->render('contact.html.twig', array(
'form' => $form->createView(),
));
However on form submit I get presented with an error:
Call to undefined method Symfony\\Component\\Validator\\ExecutionContext::getValidator()
in /home/user/project/vendor/symfony/form/Symfony
/Component/Form/Extension/Validator/Constraints/FormValidator.php on line 56
I am registering the ValidatorServiceProvider as above, so I am stumped to what it could be.
It looks to be a Symfony bug. Backporting this commit fixed it for me.
to fix it update you composer.json to specify symfony 2.5.2 :
"symfony/symfony": "2.5.2",
instead of
"symfony/symfony": "~2.5",
Then move composer.lock to composer.lock.bak and run
composer update symfony/symfony
That solved the problem for me.
Or you can wait for symfony 2.5.4 that should solve this problem :
https://github.com/symfony/symfony/issues/11580
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With