Buenas,
Intento realizar una redirección una vez terminado el envío del formulario, pero me salta un error todo el tiempo. Lo he intentado realizar de diversas formas, pero no encuentro la solución. Viendo la documentación, incluso haciendo lo mismo que allí se indica, no hay forma de hacer la redirección.
Type error: Argument 1 passed to Symfony\Component\Form\FormRenderer::renderBlock() must be an instance of Symfony\Component\Form\FormView, instance of Symfony\Component\HttpFoundation\RedirectResponse given
public function indexAction(Request $request) {
$sendOk = NULL;
if($request->get('ok') != NULL){
$sendOk = $request->get('ok');
}
if($sendOk != NULL){
return $this->render('FrontendBundle:Contact:contact.html.twig', array(
'form' => $this->generateFormAction($request),
'ok' => $sendOk
)
);
}else{
return $this->render('FrontendBundle:Contact:contact.html.twig', array(
'form' => $this->generateFormAction($request)
)
);
}
}
public function generateFormAction(Request $request) {
$form = $this->createFormBuilder()
->add('name', TextType::class, array(
'label_attr' => array('class' => 'control-label'),
'attr' => array('placeholder' => 'form.contact.placeholder.name', 'class' => 'form-control'),
'constraints' => array(
new NotBlank(array("message" => "Por favor, indique un nombre")),),
'label' => 'form.contact.name',
))
->add('surname', TextType::class, array(
'label_attr' => array('class' => 'col-sm-2 control-label'),
'attr' => array('placeholder' => 'form.contact.placeholder.surname', 'class' => 'form-control'),
'constraints' => array(
new NotBlank(array("message" => "Por favor, indique sus apellidos")),),
'label' => 'form.contact.surname',
))
->add('email', EmailType::class, array(
'label_attr' => array('class' => 'col-sm-2 control-label'),
'attr' => array('placeholder' => 'form.contact.placeholder.email', 'class' => 'form-control'),
'constraints' => array(
new NotBlank(array("message" => "Por favor, indique un email válido")),
new Email(array("message" => "Su email no parece ser válido")),),
'label' => 'form.contact.email',
))
->add('phone', NumberType::class, array(
'required' => false,
'label_attr' => array('class' => 'col-sm-2 control-label'),
'attr' => array('placeholder' => 'form.contact.placeholder.phone', 'class' => 'form-control', 'novalidate' => 'novalidate'),
'label' => 'form.contact.phone',
))
->add('message', TextareaType::class, array(
'label_attr' => array('class' => 'control-label'),
'attr' => array('placeholder' => 'form.contact.placeholder.message', 'class' => 'textarea form-control'),
'constraints' => array(
new NotBlank(array("message" => "Por favor, escriba su mensaje")),),
'label' => 'form.contact.message',
))
->add('send', SubmitType::class, array(
'attr' => array('class' => 'btn btn-default', 'onclick' => 'openPopup()'),
'label' => 'form.contact.send'))
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$data = $form->getData();
$response = $this->sendMailAction($data);
return $this->redirectToRoute('f_contact', array('ok' => $response));
}
return $form->createView();
}