欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

自定義drupal注冊表單的方法

  發(fā)布時間:2014-11-07 12:01:37   作者:佚名   我要評論
這篇文章主要為大家介紹了自定義drupal注冊表單的方法,通過user鉤子實(shí)現(xiàn)對用戶注冊信息項(xiàng)的靈活控制,是進(jìn)行drupal建站時非常實(shí)用的技巧,需要的朋友可以參考下

本文實(shí)例講述了自定義drupal注冊表單的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

drupal默認(rèn)用戶注冊表單中只有用戶名稱,帳號密碼,郵箱等字段,如果想對用戶做一些好的交互,必須要用到用戶一些稍微詳細(xì)的信息,而drupal的hook_user可以很方便的讓我們添加這些信息,比如我的站點(diǎn)要給用戶加入性別、詳細(xì)地址和個人簡介,我們可以實(shí)現(xiàn)user鉤子如下(我的模塊叫snippet):

注:本人對于字符串都沒有加t函數(shù)做翻譯,是為了提高速度,需要的用戶可以適當(dāng)修改。

復(fù)制代碼
代碼如下:
function snippet_user($op, &$edit, &$user, $category = NULL) {
switch ($op) {
// User is registering.
case 'register':
// Add a field set to the user registration form.
$fields['personal_profile'] = array(
'#type' => 'fieldset',
'#title' => '個人資料(可選)',
);
$fields['personal_profile']['sex'] = array(
'#title' => '性別',
'#type' => 'radios',
'#default_value' => 0,
'#options' => array('男' , '女')
);
$fields['personal_profile']['address'] = array(
'#type' => 'textfield',
'#title' => '現(xiàn)居住地址',
);
$fields['personal_profile']['introduction'] = array('#title' => '個人介紹', '#type' => 'textarea', '#rows' => 5, '#cols' => 50);
return $fields;
case 'form':
$fields['personal_profile'] = array(
'#type' => 'fieldset',
'#title' => '個人資料(可選)',
'#weight' => 1,
);
$fields['personal_profile']['sex'] = array(
'#title' => '性別',
'#type' => 'radios',
'#default_value' => 0,
'#options' => array('男' , '女'),
'#default_value' => $user->sex,
);
$fields['personal_profile']['address'] = array(
'#type' => 'textfield',
'#title' => '現(xiàn)居住地址',
'#default_value' => $user->address,
);
$fields['personal_profile']['introduction'] = array(
'#title' => '個人介紹',
'#type' => 'textarea',
'#rows' => 5,
'#cols' => 50,
'#default_value' => $user->introduction
);
return $fields;
}
}

 
其中的register這個op控制用戶注冊表單,而form這個op控制用戶編輯自己個人資料的表單。form只是比register加入了一些默認(rèn)值而已,而這些默認(rèn)值是從登錄用戶的user對象中讀取的,很簡單吧。

最后,如果你只是一個drupal使用者,不妨可以使用drupal內(nèi)置的profile模塊,手動配置和添加,更方便。

希望本文所述對大家的drupal建站有所幫助。

相關(guān)文章

最新評論