How can I render a form built with Silex FormServiceProvider
without using twig?
I tried both $form
and $form->createView()
, I also looked at the API documentation for both Form and FormView and it is not abvious to me how can I do that.
Here is my code:
$app->get('/form', function (Request $request) use ($app) {
// some default data for when the form is displayed the first time
$data = array(
'name' => 'Your name',
'email' => 'Your email',
);
$form = $app['form.factory']->createBuilder(FormType::class, $data)
->add('name')
->add('email')
->add('billing_plan', ChoiceType::class, array(
'choices' => array(
1 => 'free',
2 => 'small_business',
3 => 'corporate'
),
'expanded' => true,
))
->getForm();
$form->handleRequest($request);
// I want return the form here
return 'ok';
});