我在这里做错了什么?当我按下此表单上的提交按钮(Symfony 2.8)时,没有任何反应。这是控制器:
<?php
// src/AppBundle/Controller/SetuporgController.php
namespace AppBundle\Controller;
use AppBundle\Entity\Organisation;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\DateType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class SetuporgController extends Controller
{
/**
* @Route("/organisation/setup", name="setuporg")
*/
public function newAction(Request $request)
{
$organisation = new Organisation();
$form = $this->createFormBuilder($organisation)
->add('name', TextType::class)
->add('email_reminders_on', CheckboxType::class)
->add('email_reminder_frequency', ChoiceType::class, array (
'choices' => array(
'fortnightly' => 'fortnightly',
'weekly' => 'weekly',
'daily' => 'daily',
),
'choices_as_values' => true,
))
->add('save', SubmitType::class, array('label' => 'Save Changes'))
->getForm();
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($organisation);
$em->flush();
return new Response('Organisation created successfully');
}
return $this->render('default/testform.html.twig', array(
'form' => $form->createView(),
));
}
}
目前我正在测试
{{ form(form) }}
在模板中。一切看起来都不错,但按下按钮什么都不做。我正在关注文档,但我不清楚我错过了什么。我已经尝试将该方法明确地添加为POST,但这并没有改变任何东西。我已经阅读了类似这个问题的其他问题,他们都有不同的问题。