Hello all,

I have created a panel that override the individual node display and I have included the author profile on it. Now I would like to embed the author contact form in the panel in order to enable the visitor to directly contact the author of the node.

Do you know how I can do that ?

By the way thak you for this great module !

Comments

merlinofchaos’s picture

Category: support » feature

You'll have to write a new content type that takes a user context and provides the contact form. This would be a pretty good one to include with Panels, so I'm switching this to a feature request. It's not terribly difficult to do, I don't think, with a little bit of know-how.

ineation’s picture

Thanks for your support.

Christopher Herberte’s picture

subscribe

Mike_Waters’s picture

You could use the Content Template module to accomplish this (it's what I do).
I set up a module with the form's fapi code in it, then created a dummy content type and one node of that type. In that content type's template, I invoke drupal_get_form('form name') and remove everything else. Just display that dummy node in your panel, and you will get your form.

A side benefit of this is that by specifying that the panel only display the node's teaser (panel settings), and specifying different templates for the teaser and page display, you can control access to the dummy node's URL (page view). This is useful if you want the form to only display in the panel (in this case set the page template to header("Location: anotherurl") ) or if you want to theme the page display differently. Truly a hack, but a useful one.

cruzinxxx’s picture

Hi Mike,

I'm new to drupal and php. I understand the idea behind what u've done above and I want to implement the exact same thing, but I do not know how to implement it. Could you post the code and the instructions that I would need to follow to make what you've described above work.
Any help would be appreciated.

Thank you for your time
Jen

Mike_Waters’s picture

In order to create a form in Drupal 6, you need to create a custom module that contains the code required to build the form.
Here are some resources for a beginner:
Forms API Quickstart Guide
Ten Example Forms

At the very least you need to create one function in your module: the function that defines your form's structure (in an array), without defining any of it's behavior (which will require one or more additional functions, like a submit handler, a validation handler, and a menu/url handler). Let's say for the sake of this example that this function is called "test_form".

So you've created your module, that contains the function "test_form()" that describes a custom form with a few text fields and a submit button that does nothing. If you want Drupal to render your form anywhere in your site, you must use some php code to invoke the function drupal_get_form, passing the name of the function that defines your form as an argument: ex) drupal_get_form('test_form');. This code can be pretty much anywhere.

The method that I described in my post, that allows you to display your form inside of a panel, utilizes the Content Template module which overrides the data that is sent to your template files for a specific content type. Let's say for the sake of this example that a teaser display of content type "Story" is sent to the template system as the variable $node->teaser. You could use the Content Template module to override this behavior, for example to send the entire $node to the template system, or even to wrap the $node->teaser variable inside of a table, or a div, or whatever. We are leveraging this behavior to completely remove the node content from ever being displayed for a certain content type, and instead we are invoking the drupal_get_form() function to display our form.
How we do this is by creating a dummy content type using CCK, creating one node of this content type,save it, and then edit the template for our dummy content type to remove all the data that is normally sent, replacing it with the following:

<?php drupal_get_form('test_form'); ?> 

So, any time our dummy node is viewed anywhere in the system, we will see our form instead.

Fortunately for us, Panels allows us to embed any node into a panel. We just embed our dummy node into the desired panel, and instead of displaying the node, it will render our form.

HTH.

R.Hendel’s picture

subscribe

tallsimon’s picture

tomlobato’s picture

Category: feature » support

Hi Mike! Thank you, nice hints!
You`ve mentioned the method of your blog post. What is the url of this post?

Mike_Waters’s picture

I was referring to post #4 in this thread (my previous post).

tomlobato’s picture

Ok. Now I got it working (almost), but preceding the drupal_get_form with a print and
only in the teaser field of contempalte, not body field:

print drupal_get_form('my_module_my_form')

"Almost" working, because the form is shown below the title/date and above the
comment link of the node. How to get rid of these node elements so it shows only the form?

tomlobato’s picture

Now I got it.
Before, I was using drupal_get_form() in the contemplate teaser box, what just changed the teaser, keeping title, date and comments links.
After read that I can change the template file node.tpl.php for a custom content type, it got easy.
I will resume the steps:

1) Create the form using form api (I used module name my_module and form name my_form).
2) Create a new content type (say, called "forms").
3) In the theme folder, where there is a node.tpl.php file, create a file called node-forms.tpl.php and write only a line inside it:
print drupal_get_form('my_module_my_form')
4) Create a node of this content type, called, say, form_teste.

Now you can use your form inside panels, just inserting "a existing node", and pick up "form_teste" from select field (in my case, a autocomplete field).

Thank you, Mike Waters, for the great help.

Mike_Waters’s picture

NP tom. Great idea using a template file instead of the Contemplate module!

tomlobato’s picture

In really, I had to do in this way because only using contenplate I was not able to get rid of all node fields like title, date, etc. If there is a way, please, tell me.

The way I wrote in my post worked, but had a little problem. For each form I need, a new content type I have to create.
Then, I changed the template file so it call the form depending of the node content. I know, too depth into the "gambiarra" (as we call here in Brazil :), but works and keeps my content type list clean. So, my node-forms-tlp.php turns to:

  $form_name = trim( strip_tags( $node->content[body]['#value'] ) );
  print drupal_get_form($form_name);

Now, if I create a new form, I just have to create a new node of the type Forms for put it into panels.

Mike_Waters’s picture

In Contemplate, as long as you override both the teaser and node view, it should only render what you have typed in those textboxes.
In this case, the form.

And you might not have to create a new content type for each form; what you might be able to do is use a switch statement in the Contemplate textbox or in the template file (your method).
Because you are hooking into the templating layer, you have access to anything that a template file would have access to (like node->nid, url() or whatever), so your switch statement can examine the page and render one form or another based on that info.
Here is my code, as-is:

<?php 
switch ($node->nid) {
case 133:  // front page contact form
print drupal_get_form('drugsettlement_contact_form'); 
break;
case 136:  // twilio contact form
print drupal_get_form('twilio_clicktocall_form');
break;
case 137:  // contact form opener button
print drupal_get_form('drugsettlement_contact_button');
break;
}
?>

A hack, yes. ;)

merlinofchaos’s picture

Status: Active » Closed (won't fix)

With the release of Drupal 7, Drupal 5 is no longer supported.

ifernando’s picture

You have to enable the Contact module, and it appears as a new Widget in the "Add Content" button of the pane.