
How to insert a contact form inside a content Drupal 8? Or on a specific page in a specific location ? By default, contact forms created have a dedicated page. But if we want to use them elsewhere. After some research, I almost thought I should write a few lines of code to create a specific Plugin.
But contact forms, like almost everything now in Drupal 8, are entities. Finally, place a contact form, or any other form besides, is a simplicity that had eluded me until now.
No need of Panels, Display Suite or some custom preprocess functions. We will just need the Contact storage module, whose primary purpose is to extend the contact forms to store in the database their different bids, and we will see a little further, which add a little icing on the cake .
Discover how to inject a contact form inside content. This method can as well be used on any fieldable entity, such as blocks, for example.
Step 1: We add an Entity Reference type field, and select the Other option.

And we give it a label.

Step 2: After saving, we can select the entity we want to reference. We select the entity Contact form.

Step 3: We then get the field configuration page. We can keep the default options.

Step 4: After adding the field, we set up the display formatter for our field (in the manage display page configuration of the content type). We select the formatter Rendered entity for our contact field. This is where the Contact storage module step in by adding into the field formatter the Rendered entity option for displaying directly the contact form. Option which by default is not available.

Step 5: And that's it!
We just need now to create our content, and select the form, we want to display, in the autocomplete field.

And we have our content with the form available for your visitors. We can of course, for each created content, select a different form.

If you want to place your form on some others pages, simply do the same with a block, which you can then place where you want. And all this without any line of code. Effective not ?
Commentaires
There is a better way - get…
There is a better way - get used to entity_embed module, it has a cool feature about embedding entities into WYSIWYG editor
Thanks for your input. There…
Thanks for your input. There so many ways to do one thing with Drupal :-)
This is its strength. And each way has its own strengths and weaknesses.
form not showing on node
Hello Fabrice,
Thank you for the easy to follow tutorial. However, the form is not showing up on the node of content-type. link: http://be-in-charge.fr/node/3 . I tried pulling it up using views... nothing. Am I missing something?
The configuration is : Drupal core 8.1.8 and Contact Storage 8.x-1.0-beta7
Thanks for any pointers.
Hello, I will check if there…
Hello, I will check if there is still available on these version. Contact storage is a module which changes quickly. But, first, have you checked that the permissions are correctly set for the contact forms ?
It's seems that it is now…
It's seems that it is now working on your website ? A feedback about your issue ?
Genius - thank you!
This is perfect - gives me webform back!
I can see how entity_embed would be an option, and perhaps a good solution - but it's not what I wanted... This gives me exactly the replacement of webforms in D7.
Thank You!!
There isnt exist that…
There isnt exist that display mode for forms right now.
You need Contact storage…
You need Contact storage enabled to have this display mode.
Rendered entity does not appear in manage display format
Hi, I don't know why, but Rendered entity does not appear in manage display format?
I followed all the steps ... Can someone help me?
Rendered entity does not appear in manage display format
Sorry i realize too late, juste need Contact storage enabled
https://www.drupal.org/project/contact_storage
Thank you for the tutorial!
nice
nice
Autocomplete
Is it possible to hide the contact while creating the content ?
Sure. You can hide the field…
Sure. You can hide the field which reference the contact form with a hook_form_alter() (#access property), and set a default value to the field.
Add the user personal contact form to the user page
Hi.
I'm trying to add the user personal contact form to the user page so that anyone can dircetly contact a user through the personnal contact form.
Everything seems ok using the way you explained above : in each user form I can choose "Personal contact form (personal)" and save.
But when returning to the user page form the Contact field is marked : "- Restricted access - (personal)"
And when displaying the user page, the form doesn't show up (even for user admin).
The "Use users' personal contact forms " permission is checked.
If choosing any other contact form (like "Website Feedback (feedback)") it is working fine.
Do you have any idea on what is going wrong ?
Thanks.
How to make this work on views
Hi, Thanks for the tutorial. I have followed the instructions. Works perfect on a single node.
But I need to create a view of my content type and include title (plus one field) value in message body.
Any help is appreciated to fix this issue.
Thanks
Does not work, assistance needed
Hi, thanks for the tutorial. I'm experiencing some issue with this.
I would like to create a new content type that include a personal contact form so visitor can send a message to the node author.
I installed and enabled contact_storage module and followed the steps. No error message. When I create the node, I can select which contact form I would like to use. I did chose "personal contact form" (I'm using French version, so maybe it's not the proper English translation, but anyway that's one of the default contact form provided by drupal instal). This indicates to me that the field seems to be correctly configured.
I checked permissions and everything looks fine.
But when I display the node, nothing is shown. I do not know what to check... Please help
You can not use a personal…
You can not use a personal contact form on node. This is a special contact form which works only when displayed in a user context.
Rendered entity does not appear in manage display - bis
Hi, as Rosato:
I don't know why, but Rendered entity does not appear in manage display.
Though, I have contact storage enabled (enable it in extensions admin after extracting manually the archive in the modules folder, since "Install module from URL fails" for me locally.
Works great thanks a lot
You just saved me hours, thanks a lot for this !
Not rendering on node content
Hey, first of all, thanks for the great tutorial!
I'm having an issue that I really have no idea why it's happening. I followed the tutorial, selected the form on my page, when I placed the field using Layout Builder, it renders on Layout Builder page with no problems, however when I access the actual node page, it just won't render the form. Any ideas on what might cause this?
Ajouter un commentaire