Problem/Motivation

Submit message button is hardcoded but there are other uses for contact forms.
Preview button always displays but sometimes you don't want it.

Proposed resolution

Add new properties to ContactForm entity - button text and show preview
Add these to the contact form schema
Add new fields to edit form to set the values
Alter the message form to use these new values to set the button text and preview visibility
Test coverage

Remaining tasks

All of the above
You can borrow elements from contact storage module

User interface changes

New form options in contact form edit form

API changes

None

Data model changes

None

Original report

We would like to request more options to edit the buttons through the Contact Form UI in Drupal 8:

Request #1: We would like to change the text of the contact form's submit button from "Send Message" to something else within the UI since we'd hope to use this module for several diverse small forms on our site. For instance, we have one form that's a Demo Download so "Get Download" makes more sense.

Request #2: We would like to either hide or remove the preview button within the UI as it's not always needed on our forms.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jayhawkfan75 created an issue. See original summary.

ajalan065’s picture

Status: Active » Needs review
FileSize
1.39 KB

Hi jayhawkfan75,
Regarding your first point, according to me, changing the text of the button in the code would make more sense, rather than asking for an input for the button type.
However, the second point is definitely an important requirement, hence attaching the patch for the purpose.
After applying the patch, you need to perform these simple steps:
1. Login as admin
2. Go to admin/people/permissions, and give the permissions to the roles, you want to allow access to the preview button.

ajalan065’s picture

Status: Needs review » Closed (fixed)

At this point of time, I am closing the issue, as it serves your purpose.
Feel free to re-open the issue if you have further requirements regarding this topic.

katannshaw’s picture

Status: Closed (fixed) » Active

Hi ajalan065,

I'm not sure if the provided patch solves the issue for everyone as I was requesting a checkbox to toggle on/off the Preview button for each contact form for all users, anonymous and authenticated.

The other request concerns having the option to change the text of the button easily within the UI as well. In the meantime, I've been able to come up with a workaround through the theme by using this code:

function MY_SUBTHEME_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if (in_array($form_id, ['contact_message_feedback_form', ])) {
    $key = ($form_id == 'contact_message_feedback_form') ? 'actions' : 'basic';
    $form[$key]['submit']['#value'] = 'Submit My Form';
    $form[$key]['preview']['#access'] = FALSE;
  }
}
Soundvessel’s picture

The ability to change the submit button text through the UI has a lot of merit. Consider if we should be asking our site owners and SEO experts to buy development time to change something so simple in code.

larowlan’s picture

Worth noting that contact_storage has both these features

katannshaw’s picture

@larowlan: Very nice! Thank you. I hadn't seen that in my search of the core contact form and wouldn't think of looking on the Contact Storage project page.

Better documentation would be nice on the core modules and the Contact Form module itself by its maintainers since they know the ins and outs of how both modules work together now.

katannshaw’s picture

Status: Active » Closed (won't fix)
larowlan’s picture

Status: Closed (won't fix) » Postponed
Issue tags: +Contact Roadmap

We want to bring bits of contact_storage to core

larowlan’s picture

Title: Change "Send Message" text on submit button/Remove or hide Preview button » Allow changing the 'Send message' contact form string and optionally hiding the preview button
Version: 8.0.5 » 8.2.x-dev
Issue summary: View changes
Status: Postponed » Active
Issue tags: +DevDaysMilan
Parent issue: » #2582955: Contact module roadmap: 80% usecase of webforms in core
katannshaw’s picture

@larowlan,

That's great to hear. Let me know if you need me to test anything out. I'm game.

zserno’s picture

Status: Active » Needs work
FileSize
5.25 KB

Here's a first try at this issue. I took a look at contact_storage module to implement the requested features. Test coverage is still missing but code reviews are much appreciated.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ipwa’s picture

Would like to see this in core.

ja09’s picture

Also believe this is better with a core solution and shouldn't require an additional module.

ToxaViking’s picture

We don`t need show preview checkbox. It`s duplicated.

steniya’s picture

contact storage module help to over come this issue

Berdir’s picture

  1. +++ b/core/modules/contact/src/ContactFormEditForm.php
    @@ -88,6 +88,18 @@ public function form(array $form, FormStateInterface $form_state) {
    +      '#title' => t('Submit button text'),
    +      '#description' => t("Override the submit button's default <em>Send message</em> text."),
    +      '#default_value' => $contact_form->getSubmitText(),
    

    use $this->t()

  2. +++ b/core/modules/contact/src/Entity/ContactForm.php
    @@ -112,6 +128,39 @@ public function setReply($reply) {
        * {@inheritdoc}
        */
    +  public function getShowPreview() {
    +    return $this->show_preview;
    +  }
    ...
    +   * {@inheritdoc}
    +   */
    +  public function getSubmitText() {
    +    if ($this->submit_text === '') {
    +      return t('Send message');
    +    }
    

    the get methods aren't defined on the interface

katannshaw’s picture

As the author of this I'd request the following from the maintainer:
git commit -m 'Issue #2689265 by ajalan065, ToxaViking, zserno, jayhawkfan75: Allow changing the '\''Send message'\'' contact form string and optionally hiding the preview button' --author="git <git@1823508.no-reply.drupal.org>"

Let me know if that's now how it's done.

sidharthap’s picture

Status: Needs work » Needs review
FileSize
5.57 KB

I tried to apply the patch #16, it shows error in 8.3.x branch. fatal: corrupt patch at line 35
I have created a updated patch as per the comment #18.

Status: Needs review » Needs work

The last submitted patch, 20: allow_changing_the-2689265-20.patch, failed testing.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

kowalr’s picture

Anyone get this working for 8.3.5?

gnuget’s picture

Anyone get this working for 8.3.5?

You can use contact_storage in the meanwhile, that module contain the features mentioned in this issue.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

katannshaw’s picture

Status: Needs work » Fixed

Both of these requests have been fixed in the newest versions of the contact module so I'm closing this ticket. If the "fixed" status is incorrect please let me know.

katannshaw’s picture

Status: Fixed » Closed (fixed)

Changed to Closed (fixed). Let me know if that's incorrect.

gnuget’s picture

Hi jayhawkfan75,

You don't need to move the issue from "Fixed" to closed (fixed) that is automatically done by Drupal.org after a few days of inactivity and that is because once the issue is closed we cannot re-open it and in case that it needs more work we will need to create another issue or ask directly to a maintainer to do it for us.

Sadly, this is not done, right now the way to do it is installing: https://www.drupal.org/project/contact_storage, Drupal out of the box doesn't do it yet.

Can you try to re-open the issue, please?

katannshaw’s picture

Sorry about that. It's telling me that only the maintainers can reopen. @larowlan: Can you please reopen this issue for me?

Kat

Berdir’s picture

Status: Closed (fixed) » Needs work

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ckaotik’s picture

For the custom submit button text I wonder how many people actually need this feature. In most cases I've only encountered 1-2 contact forms which can share the submit button text. It can then be changed using the locale module's string translation UI. If that is not enough, we often work around this limitation using a custom hook_form_alter in either the theme or a module.

Regarding the feature to hide the preview button: In Core's contact module, we already have the intention to allow hiding the "Preview" element using the form display configuration. Unfortunately that's not quite working, but is being worked on in #2960353: Make the Preview button on the Contact Forms to obey the "Manage form display" field settings ;) I personally think that solution is much cleaner than providing yet another setting (like contact_storage's show_preview) on the entity config.
Even if we decided against Core's current approach, we'd still have to remove the preview extra field code and possibly write an update hook to convert "hidden preview form element" into "unchecked show_preview entity setting".

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

gaurav-mathur’s picture

Status: Needs work » Needs review
FileSize
30.99 KB
21.79 KB

Patch #20 tested and applied successfully for drupal 9.5.x version.
Screenshots attached for reference.

Manoj Raj.R’s picture

Is this still applicable to be feature request for Contact Module?

quietone’s picture

Status: Needs review » Needs work

The latest patch here is 6 years old and has failing tests. This is not ready for a review.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.