diff --git a/Configuration/FormConfiguration.php b/Configuration/FormConfiguration.php index e910fddd..03ac8618 100644 --- a/Configuration/FormConfiguration.php +++ b/Configuration/FormConfiguration.php @@ -36,6 +36,11 @@ class FormConfiguration implements FormConfigurationInterface */ private $fileSave = true; + /** + * @var string|null + */ + private ?string $successRedirect = null; + /** * @var MailConfigurationInterface */ @@ -148,4 +153,16 @@ public function setSave(bool $save): self return $this; } + + public function getSuccessRedirect(): ?string + { + return $this->successRedirect; + } + + public function setSuccessRedirect(?string $successRedirect): self + { + $this->successRedirect = $successRedirect; + + return $this; + } } diff --git a/Configuration/FormConfigurationFactory.php b/Configuration/FormConfigurationFactory.php index f8ab929d..6190a3be 100644 --- a/Configuration/FormConfigurationFactory.php +++ b/Configuration/FormConfigurationFactory.php @@ -71,6 +71,7 @@ public function buildByDynamic(Dynamic $dynamic): FormConfigurationInterface $config = $this->create($locale); $config->setFileFields($this->getFileFieldsByDynamic($dynamic)); $config->setFileSave(!$translation->getDeactivateAttachmentSave()); + $config->setSuccessRedirect($translation->getTargetSuccess()); $adminMailConfiguration = $this->buildAdminMailConfigurationByDynamic($dynamic); $websiteMailConfiguration = $this->buildWebsiteMailConfigurationByDynamic($dynamic); diff --git a/Controller/FormController.php b/Controller/FormController.php index 8f69d845..c0332efd 100644 --- a/Controller/FormController.php +++ b/Controller/FormController.php @@ -327,6 +327,7 @@ private function getApiEntity(Form $entity, string $locale): array 'toName' => $translation->getToName(), 'subject' => $translation->getSubject(), 'mailText' => $translation->getMailText(), + 'targetSuccess' => $translation->getTargetSuccess(), 'submitLabel' => $translation->getSubmitLabel(), 'successText' => $translation->getSuccessText(), 'sendAttachments' => $translation->getSendAttachments(), diff --git a/Entity/Form.php b/Entity/Form.php index e67616dc..43f072bc 100644 --- a/Entity/Form.php +++ b/Entity/Form.php @@ -228,6 +228,7 @@ public function serializeForLocale(string $locale, ?Dynamic $dynamic = null): ar 'title' => $translation->getTitle(), 'subject' => $translation->getSubject(), 'mailText' => $translation->getMailText(), + 'targetSuccess' => $translation->getTargetSuccess(), 'submitLabel' => $translation->getSubmitLabel(), 'successText' => $translation->getSuccessText(), 'fromEmail' => $translation->getFromEmail(), diff --git a/Entity/FormTranslation.php b/Entity/FormTranslation.php index e63f4863..19e14078 100644 --- a/Entity/FormTranslation.php +++ b/Entity/FormTranslation.php @@ -58,6 +58,11 @@ class FormTranslation implements AuditableInterface */ private $mailText; + /** + * @var null|string + */ + private $targetSuccess; + /** * @var null|string */ @@ -202,6 +207,18 @@ public function getMailText(): ?string return $this->mailText; } + public function getTargetSuccess(): ?string + { + return $this->targetSuccess; + } + + public function setTargetSuccess(?string $targetSuccess): self + { + $this->targetSuccess = $targetSuccess; + + return $this; + } + public function setSubmitLabel(?string $submitLabel): self { $this->submitLabel = $submitLabel; diff --git a/Event/RequestListener.php b/Event/RequestListener.php index 713931e1..b8a3a23f 100644 --- a/Event/RequestListener.php +++ b/Event/RequestListener.php @@ -92,7 +92,12 @@ public function onKernelRequest(RequestEvent $event): void $dynFormSavedEvent = new DynFormSavedEvent($serializedObject, $dynamic); $this->eventDispatcher->dispatch($dynFormSavedEvent, DynFormSavedEvent::NAME); - $response = new RedirectResponse('?send=true'); + if ($form->get('targetSuccess') && !empty($form->get('targetSuccess')->getData())) { + $response = new RedirectResponse($form->get('targetSuccess')->getData()); + } else { + $response = new RedirectResponse('?send=true'); + } + $event->setResponse($response); } } diff --git a/Form/Type/DynamicFormType.php b/Form/Type/DynamicFormType.php index 201ba101..eca592dd 100644 --- a/Form/Type/DynamicFormType.php +++ b/Form/Type/DynamicFormType.php @@ -16,6 +16,7 @@ use Sulu\Bundle\FormBundle\Entity\Dynamic; use Sulu\Bundle\FormBundle\Entity\Form; use Sulu\Bundle\FormBundle\Exception\FormNotFoundException; +use Sulu\Component\Content\Mapper\ContentMapperInterface; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\EmailType; use Symfony\Component\Form\Extension\Core\Type\HiddenType; @@ -41,17 +42,24 @@ class DynamicFormType extends AbstractType */ private $honeyPotField; + /** + * @var ContentMapperInterface + */ + private $contentMapper; + /** * DynamicFormType constructor. */ public function __construct( FormFieldTypePool $typePool, Checksum $checksum, + ContentMapperInterface $contentMapper, ?string $honeyPotField = null ) { $this->typePool = $typePool; $this->checksum = $checksum; $this->honeyPotField = $honeyPotField; + $this->contentMapper = $contentMapper; } /** @@ -167,6 +175,20 @@ public function buildForm(FormBuilderInterface $builder, array $options) ); } + // Redirect URL after success + if ($translation->getTargetSuccess()) { + $contentStructure = $this->contentMapper->load( + $translation->getTargetSuccess(), + $builder->getData()->getWebspaceKey(), + $locale + ); + + $builder->add('targetSuccess', HiddenType::class, [ + 'data' => $contentStructure->getPath(), + 'mapped' => false, + ]); + } + // Add submit button. $builder->add( 'submit', diff --git a/Manager/FormManager.php b/Manager/FormManager.php index 11275c3f..873cca31 100644 --- a/Manager/FormManager.php +++ b/Manager/FormManager.php @@ -89,6 +89,7 @@ public function save(array $data, ?string $locale = null, ?int $id = null): ?For $translation->setToEmail(self::getValue($data, 'toEmail')); $translation->setToName(self::getValue($data, 'toName')); $translation->setMailText(self::getValue($data, 'mailText')); + $translation->setTargetSuccess(self::getValue($data, 'targetSuccess')); $translation->setSubmitLabel(self::getValue($data, 'submitLabel')); $translation->setSuccessText(self::getValue($data, 'successText')); $translation->setSendAttachments(self::getValue($data, 'sendAttachments', false)); diff --git a/Resources/config/doctrine/FormTranslation.orm.xml b/Resources/config/doctrine/FormTranslation.orm.xml index a9541903..aa5c1b09 100644 --- a/Resources/config/doctrine/FormTranslation.orm.xml +++ b/Resources/config/doctrine/FormTranslation.orm.xml @@ -16,6 +16,7 @@ + diff --git a/Resources/config/forms/form_details.xml b/Resources/config/forms/form_details.xml index ea5125fd..11b34541 100644 --- a/Resources/config/forms/form_details.xml +++ b/Resources/config/forms/form_details.xml @@ -22,6 +22,12 @@ + + + sulu_form.success_landing_page + + + sulu_form.submit_label diff --git a/Resources/config/services.xml b/Resources/config/services.xml index dafd868c..96e6b064 100644 --- a/Resources/config/services.xml +++ b/Resources/config/services.xml @@ -97,6 +97,7 @@ + %sulu_form.honeypot_field% @@ -175,8 +176,8 @@ @@ -231,8 +232,8 @@ + class="Sulu\Bundle\FormBundle\Controller\FormWebsiteController" + public="true"> diff --git a/Resources/translations/admin.en.json b/Resources/translations/admin.en.json index 298ce36b..37d644dc 100644 --- a/Resources/translations/admin.en.json +++ b/Resources/translations/admin.en.json @@ -79,5 +79,6 @@ "sulu_form.salutation_mr": "Mr.", "sulu_form.salutation_ms": "Ms.", "sulu_form.single_form_selection.no_form_selected": "No form selected", - "sulu_form.single_form_selection.overlay_title": "Select a form" + "sulu_form.single_form_selection.overlay_title": "Select a form", + "sulu_form.success_landing_page": "Success landing page" }