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.
Comment | File | Size | Author |
---|---|---|---|
#41 | before_patch.png.jpg | 21.79 KB | gaurav-mathur |
#41 | after-patch.jpg | 30.99 KB | gaurav-mathur |
#20 | allow_changing_the-2689265-20.patch | 5.57 KB | sidharthap |
#16 | allow_changing_the-2689265-16.patch | 5.03 KB | ToxaViking |
#12 | allow_changing_the-2689265-12.patch | 5.25 KB | zserno |
Comments
Comment #2
ajalan065 CreditAttribution: ajalan065 as a volunteer and at Google Summer of Code commentedHi 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.
Comment #3
ajalan065 CreditAttribution: ajalan065 as a volunteer and at Google Summer of Code commentedAt 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.
Comment #4
katannshaw CreditAttribution: katannshaw commentedHi 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:
Comment #5
Soundvessel CreditAttribution: Soundvessel commentedThe 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.
Comment #6
larowlanWorth noting that contact_storage has both these features
Comment #7
katannshaw CreditAttribution: katannshaw commented@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.
Comment #8
katannshaw CreditAttribution: katannshaw commentedComment #9
larowlanWe want to bring bits of contact_storage to core
Comment #10
larowlanComment #11
katannshaw CreditAttribution: katannshaw commented@larowlan,
That's great to hear. Let me know if you need me to test anything out. I'm game.
Comment #12
zserno CreditAttribution: zserno as a volunteer commentedHere'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.
Comment #14
ipwa CreditAttribution: ipwa commentedWould like to see this in core.
Comment #15
ja09 CreditAttribution: ja09 commentedAlso believe this is better with a core solution and shouldn't require an additional module.
Comment #16
ToxaViking CreditAttribution: ToxaViking commentedWe don`t need show preview checkbox. It`s duplicated.
Comment #17
steniya CreditAttribution: steniya commentedcontact storage module help to over come this issue
Comment #18
Berdiruse $this->t()
the get methods aren't defined on the interface
Comment #19
katannshaw CreditAttribution: katannshaw at Promet Source commentedAs 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.
Comment #20
sidharthapI 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.
Comment #23
kowalr CreditAttribution: kowalr commentedAnyone get this working for 8.3.5?
Comment #24
gnugetYou can use contact_storage in the meanwhile, that module contain the features mentioned in this issue.
Comment #26
katannshaw CreditAttribution: katannshaw at Promet Source commentedBoth 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.
Comment #27
katannshaw CreditAttribution: katannshaw at Promet Source commentedChanged to Closed (fixed). Let me know if that's incorrect.
Comment #28
gnugetHi 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?
Comment #29
katannshaw CreditAttribution: katannshaw at Promet Source commentedSorry about that. It's telling me that only the maintainers can reopen. @larowlan: Can you please reopen this issue for me?
Kat
Comment #30
BerdirComment #32
ckaotikFor 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".Comment #41
gaurav-mathur CreditAttribution: gaurav-mathur at Dotsquares Ltd. commentedPatch #20 tested and applied successfully for drupal 9.5.x version.
Screenshots attached for reference.
Comment #42
Manoj Raj.R CreditAttribution: Manoj Raj.R as a volunteer and at ITT Digital commentedIs this still applicable to be feature request for Contact Module?
Comment #43
quietone CreditAttribution: quietone at PreviousNext commentedThe latest patch here is 6 years old and has failing tests. This is not ready for a review.