Getting POST Data for Pimcore Mail (Pimcore 5)

Hello there. We are setting up a contactform. in pimcore 4 we used this to get the POST data:

if ($this->_request->isPost()) {
$params = $this->_request->getPost();
}

In pimcore 5 with symfony that doesn’t work anymore. can you tell me how to get the POST data in PC5?
Thanks!

Hi @sandra-walker,

First you create your form in your controller and tell it to handle the request. Then you can check if your form has been submitted and is valid and then get the data from it. The code could look something like this.

public function contactAction(Request $request)
{
    $form = $this->createForm(ContactFormType::class);
    $form->handleRequest($request);

    if ($form->isSubmitted() && $form->isValid()) {
        $data = $form->getData();
        // do with the data here whatever you need

        return $this->redirect('/'); // make sure to redirect the user after form submission
    }
    
    return $this->renderTemplate('Contact/form.html.twig', [
        'form' => $form->createView(),
    ]);
}

Hope this helps!

Thanks for your time.

the document we created was send with no problem. so we already recieve a mail from pimcore mail.
also post data is visible in development tools. i think we have a problem with the form itself.
we used this placeholder. (printscreen). can you see something wrong there?

contactform

Are you calling $mail->setParams($params); in your email action? This enables the %Text() placeholders within email templates. Your code should look something like this:

public function contactAction(Request $request)
{
    $form = $this->createForm(ContactFormType::class);
    $form->handleRequest($request);

    if ($form->isSubmitted() && $form->isValid()) {
        $data = $form->getData();
        
        $mail = new Mail();
        $mail->addTo('example@pimcore.org');
        $mail->setDocument('/email/my-email-document');
        $mail->setParams($data); // the $data should include 'first_name', 'email' and the other fields
        $mail->send();

        return $this->redirect('/'); // make sure to redirect the user after form submission
    }
    
    return $this->renderTemplate('Contact/form.html.twig', [
        'form' => $form->createView(),
    ]);
}