Why would you want to do this?
- Contact page becomes a node, with all the benefits that implies
- Easier to maintain and edit its content and permissions can be assigned
Step 1 of 3
Add in your theme's template.php
the following code which allows node-specific theming
function phptemplate_preprocess_node(&$vars) {
$vars['template_files'][] = 'node-'. $vars['nid'];
return $vars;
}
Clear the cache so the function can be noticed by the system since this is technically an override.
Note that Drupal maintains cached theming data through the theme registry. It must be cleared when setting up overrides. (read more about how theming works)
Step 2 of 3
Create a node which will serve as your contact page
and note the node-id after creation. Lets assume its 38
in this example
Step 3 of 3
Create node-38.tpl.php
in your theme's directory and add the following code in it
require_once drupal_get_path('module', 'contact') .'/contact.pages.inc';
//no need to maintain two version of node.tpl.php
include "node.tpl.php";
function local_contact_page(){
$form = contact_mail_page();
// override default values here if you want
// next one will select a different category
//$form['cid']['#default_value'] = 0;
return($form);
}
function local_contact_page_submit($form_id, $form_values){
return(contact_mail_page_submit($form_id, $form_values));
}
function local_contact_page_validate($form, $form_state){
return(contact_mail_page_validate($form, $form_state));
}
print drupal_get_form('local_contact_page');
NOTES
This is one way of doing this; if you need to modify the contact form itself, you can do so in the local_contact_page()
but your best bet would be webform module.
If you know the changes needed for this to work in Drupal 5 please go ahead and edit this page but, one can probably figure it out by looking at the page that inspired me Quick Contact Block
Comments
Embed a Forward Form in a node.
I've successfully modified this excellent snippet to allow embedding of a forward form in a node. This is useful if you want to encourage users to forward specific content. For instance, after signing a petition users can be redirected to a new page that asks them to send the petition to their friends and family.
To implement this, I used the following code in the node-x.tpl.php file (Step 3). Steps 1 and 2 remain the same.
Combining with contact_redirect
If you use the module Contact Redirect (http://drupal.org/project/contact_redirect) you can get it to work with this solution by amending the function local_contact_page to the following:
Does not work..!
I tried to follow your steps, and I think i did everything perfectly well, but it does not work!
Does anyone know what can be wrong?
I hoped the contactform would appear on my node-13:
http://www.mooiebeloftes.nl/nl/node/13
Any help would be very welcome!
UPDATE:
It does work however with just entering this code in the text-field of the page: (and setting the page to php)
for D7
Great - just what I was looking for.
For D7:
solved.
solved.
thats is realy good
Thanks! This works perfectly!
Thanks! This works perfectly!
Thanks
Work fine for me and all the others ways didn't worked.
need add this
require_once drupal_get_path('module', 'contact') .'/contact.module';
repair this when submit:
Fatal error: Call to undefined function contact_load() in path/contact.pages.inc on line 129
Drupal 7
This is what I did with drupal 7 to be placed under theme_preprocess_node:
Adjust NID accordingly. You can print it anywhere inside node.tpl, maybe at node--page.tpl.php:
There is also a module for this:
http://drupal.org/project/contact_form_on_node
love, light n laughter
You can also do it with
You can also do it with Panels module. Both for a page and a block (using mini-panel).
correct. It also worked for
correct. It also worked for us.