You are here

Drupal 7 中文教程 联系我们 两步表单 module 文件 代码部分

g089h515r806 的头像
Submitted by g089h515r806 on 星期四, 2011-08-18 16:00

<?php

/**
 * @file
 * 方便用户联系我们.
 */

/**
 * 实现钩子hook_menu().
 */
function contactus_menu() {
  $items = array();
 //联系我们菜单项
  $items['contactus'] = array(
    'tilte' => '联系我们',
      'page callback' => 'contactus_page',
      'type'     => MENU_CALLBACK,
      'access callback' =>TRUE,
   'file' => 'contactus.pages.inc',
  );
 //确认页面菜单项
  $items['contactus/confirm'] = array(
      'page callback' => 'contactus_confirm_page',
      'type'     => MENU_CALLBACK,
      'access callback' =>TRUE,
   'file' => 'contactus.pages.inc',
  );
 //致谢页面菜单项
  $items['contactus/thanks'] = array(
      'page callback' => 'contactus_thanks_page',
      'type'     => MENU_CALLBACK,
      'access callback' =>TRUE,
   'file' => 'contactus.pages.inc',
  );
  return $items;
}

/**
 * 实现钩子hook_mail().
 */
function contactus_mail($key, &$message, $params){
 $language = $message['language'];
  switch ($key) {
   case 'contact':
  
    //邮件的标题
    $message['subject'] = '联系我们';
   
   //邮件正文,这里面包含:姓名、单位名称、电子邮件、电话号码、邮件正文、访问来源
      $message['body'][] = '姓名:'.$params['name'];
      $message['body'][] = '单位名称:'.$params['company_name'];
      $message['body'][] = '电子邮件:'.$params['mail'];
      $message['body'][] = '电话号码:'.$params['phone'];
      $message['body'][] = '邮件正文:'.$params['contact'];
   
      //对于访问来源,如果visit的值我们选择了“其它”,那么此时我们取$params['other'],否则取$params['visit']
      $visit = "";
      if($params['visit'] == 'other'){
        $visit = $params['other'];
      }else{
        $visit = $params['visit'];
      }
      $message['body'][] = '访问来源:'. $visit;
  }
}
 

Drupal版本: