
Форма контактов в Друпал 6 (contact_mail_page) и Drupal 7 (contact_site_form)
admin сб, 30/07/2011 - 11:25
Вставить форму контактов в ноду в Drupal 6 и Drupal 7 можно так:
Без перевода.
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' => array( 'arguments' => array('form' => NULL), 'template' => 'contact-form', ), ); } function myTheme_preprocess_contact_mail_page(&$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' => array( 'render element' => 'form', 'template' => 'contact-site-form', 'path' => drupal_get_path('theme', 'myTheme').'/templates'; ), ); } function myTheme_preprocess_contact_site_form(&$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!
Комментировать