How To Add A User Contact Form To Drupal Panels

Author:
phil
Created:
Saturday, March 10th, 2012
Last Updated:
Saturday, March 10th, 2012

Disclaimer: Accessing the information on this page means you agree to the Sites Terms of Service


I recently wanted the ability to add a node authors contact form, to a panel. If you don't know what Panels are, check them out. It's the future of Drupal IMHO and panels lets you lay out a website in row/column format, dragging and dropping just about any piece of information you want. It's beautiful.

Off my sales pitch and moving on... I wanted to be able to have a user create a node from a content type, then allow people to contact the author directly from the node. In D6, I simply used "Author Contact" which worked perfectly for me but it wasn't migrated to D7. I searched for about 20 minutes, looking at for a replacement module or maybe some PHP code to just plug in but I ended up empty handed with modules that I really didn't want to mess with and no easily documented way to add the user contact form to a node.

So, I set out to try to figure it out.

After doing some playing with the contexts and relationships in panels, (I figured panels had to be smart enough to do it) I finally figured out the right combination of adding a user contact form to Panels. If you're looking to do the sitewide contact form, I dunno what to tell you, but this method might give you a start.

First off, make sure the core "Contact" module is enabled. Obviously, panels 3.x needs to be installed and it's ctools requirement.

Before you can add the user contact form, you must first add a relationship.

1) Edit your Panels template "Variant" and go to: Contexts
2) Under Relationships you will see a dropdown. Choose: User from Node (on node.node_author) then hit the Add relationship button. A settings window will appear, just click Finish
3) Click on the Update and save button at the bottom of the page.
4) Next, go to the Content section
5) Add a content like you normally would (click the little sprocket) and choose User
6) Inside the "User" content, you will now see User contact form. When you click on it, the settings window will appear and you will have the ability to choose User from Node (on node.node_author) from the pulldown. If you haven't added any other contexts or relationships, this will be the only option in the pulldown.
7) Click Finish on the content form.
8) Click the Update and save button

That's it!

On a side note, make sure that you remember to set the permissions for authenticated users and(or) anonymous users to be able to Use users' personal contact forms.

I hope this helped those of you searching for a way to add a user contact form to a node! It should technically work on D6 too since Panels 3 has been written for both versions of Drupal.

If I was able to help, feel free to drop a line in the comments!

Post Comment