useRZ\Roadiz\Core\Entities\CustomForm;useRZ\Roadiz\Core\Exceptions\EntityAlreadyExistsException;useRZ\Roadiz\Core\Exceptions\ForceResponseException;useRZ\Roadiz\Utils\CustomForm\CustomFormHelper;useSymfony\Component\Form\FormError;useSymfony\Component\HttpFoundation\JsonResponse;// …/* * Get your custom form instance from your node-source * only if you added a *custom-form reference field*. */$customForms=$this->nodeSource->getCustomformReference();if(isset($customForms[0])&&$customForms[0]instanceofCustomForm){/** @var CustomForm $customForm */$customForm=$customForms[0];/* * Verify if custom form is still open * for answers */if($customForm->isFormStillOpen()){/* * CustomFormHelper will generate Symfony form against * Roadiz custom form entity. * You can add a Google Recaptcha passing following options. */$helper=newCustomFormHelper($this->get('em'),$customForm);$form=$helper->getFormFromAnswer($this->get('formFactory'),null,true,['recaptcha_public_key'=>$this->get('settingsBag')->get('recaptcha_public_key'),'recaptcha_private_key'=>$this->get('settingsBag')->get('recaptcha_private_key'),'request'=>$request,]);$form->handleRequest($request);if($form->isSubmitted()&&$form->isValid()){try{$answer=$helper->parseAnswerFormData($form,null,$request->getClientIp());if($request->isXmlHttpRequest()){$response=newJsonResponse(['message'=>$this->getTranslator()->trans('form_has_been_successfully_sent')]);}else{$this->publishConfirmMessage($request,$this->getTranslator()->trans('form_has_been_successfully_sent'));$response=$this->redirect($this->generateUrl($this->nodeSource->getParent()));}/* * If you are in a BlockController use ForceResponseException */thrownewForceResponseException($response);/* * Or directly return redirect response. *///return $response;}catch(EntityAlreadyExistsException$e){$form->addError(newFormError($e->getMessage()));}}$this->assignation['session']['messages']=$this->get('session')->getFlashBag()->all();$this->assignation['form']=$form->createView();}}

If you didn’t do it yet, create a custom form theme in your views/ folder: