启用这个模块后,再访问127.0.0.1/?q=contactus,还要报Strict warning: Only variables should be passed by reference 在 contactus_page() (行 28 在 D:\WWW\drupal\sites\all\modules\custom\contactus\contactus.pages.inc).这种错误,而且页面上不显示表单,但我用kpr方法可以打印表单项,这是为什么呢?
contactus.module文件
/**
* Implements hook_menu().
*/
function contactus_menu() {
$items ['contactus'] = array (
'title' => '联系我们',
'description' => '这是悬浮提示',
'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;
}
contactus.pages.inc文件代码
function contactus_page() {
drupal_set_title ( '联系我们' );
$render_array = array (
'#makeup' => '',
);
$render_array['#makeup'] .= drupal_render ( drupal_get_form ( 'contactus_form' ) ) ;
kpr($render_array); //这里可以打印表单
return $render_array;
}
function contactus_form() {
$form ['tips'] = array (
'#prefix' => '<div id="tips">',
'#makeup' => t ('<span class="form-required">*</span>号为必填项'),
'#suffix' => '</div>',
);
$form ['name'] = array (
'#title' => t('姓名'),
'#type' => 'textfield',
'#required' => TRUE,
'#default_value' => isset($_SESSION['contactus_form']['name'])?$_SESSION['contactus_form']['name']:'',
'#description' => t('例如:周星弛'),
);
return $form;
}
这个不影响工作 PHP版本的问题,有的PHP版本下,
PHP版本的问题,有的PHP版本下,比较低的版本,是不会有这个警告信息的。
$render_array['#makeup'] .= drupal_render ( drupal_get_form ( 'contactus_form' ) ) ;
应该这样写:
$contactus_form =drupal_get_form ( 'contactus_form' );
$render_array['#makeup'] .= drupal_render ($contactus_form) ;
好的,这次没有报错了,但是没有显示表单的内容。
好的,这次没有报错了,但是没有显示表单的内容。
我把第一集的代码下载地址放上去了,http://www.t
我把第一集的代码下载地址放上去了,http://www.thinkindrupal.com/think-in-drupal, 你可以下载看看,怎么回事。没有看出来有什么问题。