我是symfony的新手,想要创建一个简单的联系表单,获取提交的值并将其作为电子邮件发送.我不想在数据库中保存任何内容.
我按照此页面上的文档:https://symfony.com/doc/current/form/without_class.html
我使用上面的代码创建了一个新页面/操作:
/**
* @Route("/contact", name="page_contact")
*/
public function contact(Request $request)
{
$defaultData = ['message' => 'Type your message here'];
$form = $this->createFormBuilder($defaultData)
->add('name', TextType::class)
->add('email', EmailType::class)
->add('message', TextareaType::class)
->add('send', SubmitType::class)
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// data is an array with "name", "email", and "message" keys
$data = $form->getData();
}
return $this->render('Shop/contact.html.twig', [
'form' => $form
]);
}
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误:
Symfony\Component\Form\Exception\InvalidArgumentException:
Could not load type "Doctrine\DBAL\Types\TextType": class does not implement "Symfony\Component\Form\FormTypeInterface".
at vendor/symfony/form/FormRegistry.php:89
at …Run Code Online (Sandbox Code Playgroud)