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';
});
Have you tried this : http://symfony.com/doc/2.3/book/forms.html#rendering-the-form
$formView = $form->createView();
$html = $formView->start($form) .
$formView->widget($form) .
$formView->end($form);
Truth be told, I didn't have time to check this, but it might help.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.