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
Comment #1
merlinofchaos commentedYou'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.
Comment #2
ineation commentedThanks for your support.
Comment #3
Christopher Herberte commentedsubscribe
Comment #4
Mike_Waters commentedYou 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.Comment #5
cruzinxxx commentedHi 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
Comment #6
Mike_Waters commentedIn 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:
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.
Comment #7
R.Hendel commentedsubscribe
Comment #8
tallsimon commentedor use module http://drupal.org/project/contact_form_blocks
Comment #9
tomlobato commentedHi Mike! Thank you, nice hints!
You`ve mentioned the method of your blog post. What is the url of this post?
Comment #10
Mike_Waters commentedI was referring to post #4 in this thread (my previous post).
Comment #11
tomlobato commentedOk. 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?
Comment #12
tomlobato commentedNow 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.
Comment #13
Mike_Waters commentedNP tom. Great idea using a template file instead of the Contemplate module!
Comment #14
tomlobato commentedIn 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:
Now, if I create a new form, I just have to create a new node of the type Forms for put it into panels.
Comment #15
Mike_Waters commentedIn 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:
A hack, yes. ;)
Comment #16
merlinofchaos commentedWith the release of Drupal 7, Drupal 5 is no longer supported.
Comment #17
ifernando commentedYou have to enable the Contact module, and it appears as a new Widget in the "Add Content" button of the pane.