My controller acts as if I never click on the submit button.
My controller:
public function listAction(RegionsService $service)
{
$regions = $service->getRegionList();
$editForm = $this->createForm('App\Form\RegionListType');
if ($editForm->isSubmitted())
{
dump('submitted');
die();
}
if ($editForm->isSubmitted() && $editForm->isValid()) {
$task = $editForm->getData();
dump($task);
die();
...
}
return $this->render('parameter/region.list.html.twig', [
'form' => $editForm->createView(),
'regions' => $regions
]);
...
My form :
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('regionsset', TextType::class, array(
'required' => false))
->add('save', SubmitType::class, array(
'attr' => array('class' => 'save')));
}
My view :
{{ form_start(form, {'action' : path('app_region_list')} ) }}
{{ form_widget(form.regionsset, {'attr': {'class': 'foo'}}) }}
{{ form_widget(form.save, { 'label': 'Save' }) }}
{{ form_end(form) }}
When I click on the submit button, the controller never goes into the first test if ($editForm->isSubmitted())
What did I miss ?
You forgot to handle the request in your form. After creating the form, ($editForm), you have to handle the request as follows:
$editForm->handleRequest($request);
After that, the method isSubmitted()
will return true.
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