With Roadiz you can easily create simple contact forms with ContactFormManager class. Your controller has
a convenient shortcut to create this manager with $this->createContactFormManager() method.

If you want to add your own fields, you can use the manager’ form-builder with $contactFormManager->getFormBuilder();.
Then add your field using standard Symfony form syntax. Do not forget to use Constraints to handle errors.

useSymfony\Component\Validator\Constraints\File;useSymfony\Component\Form\Extension\Core\Type\CheckboxType;useSymfony\Component\Form\Extension\Core\Type\FileType;useSymfony\Component\Form\Extension\Core\Type\SubmitType;…// Create contact-form manager and add 3 default fields.$contactFormManager=$this->createContactFormManager()->withDefaultFields();/* * (Optional) Add custom fields… */$formBuilder=$contactFormManager->getFormBuilder();$formBuilder->add('callMeBack',CheckboxType::class,['label'=>'call.me.back','required'=>false,])->add('document',FileType::class,['label'=>'document','required'=>false,'constraints'=>[newFile(['maxSize'=>$contactFormManager->getMaxFileSize(),'mimeTypes'=>$contactFormManager->getAllowedMimeTypes(),]),]])->add('send',SubmitType::class,['label'=>'send.contact.form',]);/* * This is the most important point. handle method will perform form * validation and send email. * * Handle method should return a Response object if everything is OK. */if(null!==$response=$contactFormManager->handle()){return$response;}$form=$contactFormManager->getForm();// Assignate your form view to display it in Twig.$this->assignation['contactForm']=$form->createView();

In this example, we used withDefaultFields method which add automatically email, name and message
fields with right validation contraints. This method is optional and you can add any field you want manually, just
keep in mind that you should always ask for an email.

If you want to use contact-forms in blocks instead of a full page, you will need
to make your redirection response bubble through Twig render. The only way to stop
Twig is to throw an exception and to pass your Redirect or Json response within your
Exception.

Roadiz makes this possible with RZ\Roadiz\Core\Exceptions\ForceResponseException.
For example, in a Themes\MyAwesomeTheme\Controllers\Blocks\ContactBlockController, instead of
returning the contactFormManager response, you will have to throw a ForceResponseException
with it as an argument.

Roadiz can seamlessly use Google reCAPTCHA to secure your contact form against robots.
All you need to do is to register on https://www.google.com/recaptcha/ to ask for a sitekey
and a secret. Once you’ve got these two keys, add them to your Roadiz settings.

Then, just use withGoogleRecaptcha() method on your contact-form manager.