Simple Symfony 4 Contact Form

Let's create a simple contact form using Symfony 4.

We'll capture the visitors name, email address, date of birth, and also their message.

This is a companion discussion topic for the original entry at

Did you figure it out? Was it the namespace?

Tnx for your replay, I just fixed it. I forgot to add
use App\Form\ContactType;
to ContactController.php

Hi Christ,
I’ve a serious trouble with Symfony Contact Form when dealing with search result with ElasticSearch.
The issue is that I would like to Send a Mail using this Contact Form to Search Result Entities that are for example Corporates.
In the ElasticSearch Result,

1/ The first contact form belong to the first Corporate Appear(is ok)
2/ The contact form for the rest of corporates are blank

In the Controller

In the Form (In the first contact Form)

So its like for every Corporate I must create a dedicated Form for each Corporate.
This what i try to solve a still get no way.

If you could help.


I’m not quite sure I understand your problem.

Firstly, what is a Corporate ? Is this a person in your company?

You have an array of Corporate entities. These come from ElasticSearch. Each Corporate contains an email field?

You have a contact form that works for a single Corporate, but is blank for the remaining Corporate entities? Is every field blank?

If at all possible, try and separate the contact form presentation from the data.

What I’d be tempted to do is create a ‘static’ version where you don’t use data from ElasticSearch at all. Instead, use an array of data with similar fields. Get it working with this, and then integrate with dynamic / ElasticSearch data.

If you can post more code - use backticks (`) to format code blocks - then it will give me a better idea of where you’re at currently. Or post the specific code up on GitHub and then I can take a proper look.