Problem/Motivation

Contact form is missing the feature to redirect form to custom specified URLs. There is a related core issue #306662: Add redirect option to site-wide contact forms which is trying to do something similar.

Proposed resolution

Add the option for adding custom redirect URL to contact forms after submitting.

Remaining tasks

User interface changes

API changes

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mbovan created an issue. See original summary.

mbovan’s picture

Status: Active » Needs review
FileSize
3.71 KB
13.19 KB

Here is the patch that we use in a custom module. Additionally, I added tests.

Currently, we can only redirect to the pages on the website. We should discuss if we want to allow users redirection to external websites.

UI changes:
Redirect page field

larowlan’s picture

Thank you for this patch! awesome work

  1. +++ b/contact_storage.module
    @@ -6,6 +6,52 @@
    +  if ($contact_form->getThirdPartySetting('contact_storage', 'redirect_uri', FALSE)) {
    +    $form_state->setRedirectUrl(Url::fromUri($contact_form->getThirdPartySetting('contact_storage', 'redirect_uri', FALSE)));
    

    nit: can we do:
    if ($redirect_url = $contact_form->get...) to save the two calls to ->getThirdPartySetting()?

  2. +++ b/src/Tests/ContactStorageTest.php
    @@ -84,6 +84,17 @@ class ContactStorageTest extends WebTestBase {
    +    $this->assertEqual($this->url, $admin_user->urlInfo()->setAbsolute()->toString());
    

    <3 it - this a a great patch!

larowlan’s picture

Issue summary: View changes
larowlan’s picture

Gonna fix the nit and commit

  • larowlan committed 00f46b2 on 8.x-1.x
    Issue #2584723 by mbovan, larowlan: Add a custom redirect page option to...
  • larowlan committed d1f546e on 8.x-1.x authored by mbovan
    Issue #2584723 by mbovan, larowlan: Add a custom redirect page option to...
larowlan’s picture

Status: Needs review » Fixed
FileSize
1.04 KB

Fixed, thanks

Committed with this interdiff.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

YuanZheCSYZ’s picture

Hi guys,

It seems this redirect uri only works with the default form (/contact), not when it comes to embed the form into pages nor blocks.

Any help on this? Thanks