Форма контактов в Друпал 6 (contact_mail_page) и Drupal 7 (contact_site_form)

Вставить форму контактов в ноду в Drupal 6 можно следующим образом:

<?php
  require_once drupal_get_path('module', 'contact').'/contact.pages.inc';
  print drupal_get_form('contact_mail_page');
?>

А вставить форму контактов в ноду в Drupal 7 можно так:

<?php
module_load_include('inc', 'contact', 'contact.pages');
$form = drupal_get_form('contact_site_form');
print render($form);
?>

------

Темизация формы контактов.

Без перевода.

Theming the contact form in Drupal 7 is almost the same as most people did it in Drupal 6, but the one change through me for a loop for quite awhile.

Using Drupal 6, most people would add some code to their template.php file and create something like the following:

DRUPAL 6

function myTheme_theme() {
  return array(
	'contact_mail_page' =&gt; array(
					'arguments' =&gt; array('form' =&gt; NULL),
					'template' =&gt; 'contact-form',
					),
	);
}
function myTheme_preprocess_contact_mail_page(&amp;$vars)
{
	$vars['name'] = drupal_render($vars['form']['name']);	
	$vars['email'] = drupal_render($vars['form']['mail']);
	$vars['subject'] = drupal_render($vars['form']['subject']);
	$vars['message'] = drupal_render($vars['form']['message']);
	$vars['copy'] = drupal_render($vars['form']['copy']);
	$vars['submit'] = drupal_render($vars['form']['submit']);
 
}

The Drupal 7 method is nearly the same. The contact form ID has changed to "contact_site_form" but there is also one other key change. If you simply change the form ID, and use the drupal 6 code, you will notice that your "form" element has a null key. Instead, you will need to use the following for Drupal 7:

DRUPAL 7

function myTheme_theme() {
  return array(
	'contact_site_form' =&gt; array(
					'render element' =&gt; 'form',
					'template' =&gt; 'contact-site-form',
<code>                                        'path' =&gt; drupal_get_path('theme', 'myTheme').'/templates';</code>
					),
	);
}
function myTheme_preprocess_contact_site_form(&amp;$vars)
{
	$vars['contact'] = drupal_render_children($vars['form']);
 
}

That should get you the ability to create a template file called contact-site-form.tpl.php. The path parameter is optional, but can be necessary if you aren't storing you templates in the root of your theme. Also be careful with the drupal_render function. If you want to render the rest of the form after rendering elements, or render the entire form at once, use drupal_render_children() instead. Good luck!