自定義drupal注冊表單的方法
發(fā)布時間:2014-11-07 12:01:37 作者:佚名
我要評論
這篇文章主要為大家介紹了自定義drupal注冊表單的方法,通過user鉤子實現(xiàn)對用戶注冊信息項的靈活控制,是進行drupal建站時非常實用的技巧,需要的朋友可以參考下
本文實例講述了自定義drupal注冊表單的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
drupal默認用戶注冊表單中只有用戶名稱,帳號密碼,郵箱等字段,如果想對用戶做一些好的交互,必須要用到用戶一些稍微詳細的信息,而drupal的hook_user可以很方便的讓我們添加這些信息,比如我的站點要給用戶加入性別、詳細地址和個人簡介,我們可以實現(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;
}
}
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加入了一些默認值而已,而這些默認值是從登錄用戶的user對象中讀取的,很簡單吧。
最后,如果你只是一個drupal使用者,不妨可以使用drupal內(nèi)置的profile模塊,手動配置和添加,更方便。
希望本文所述對大家的drupal建站有所幫助。
相關(guān)文章
- 真是不看不知道,Drupal 真奇妙。很多使用CMS內(nèi)容管理系統(tǒng)的人可能都會知道一款國外的CMS系統(tǒng):Drupal 。在我們傳統(tǒng)的想象中CMS除了能做內(nèi)容文章站外,其他還有圖片站,分2010-01-24
- 對頁面和靜態(tài)資源的啟用緩存和Gzip壓縮傳輸.2010-01-24
- drupal模塊開發(fā)分析,方便想要drupal模塊開發(fā)的朋友2012-12-06
drupal 自定義表單調(diào)用autocomplete主標(biāo)簽實現(xiàn)代碼
drupal 自定義表單調(diào)用autocomplete主標(biāo)簽實現(xiàn)代碼,需要的朋友可以參考下2012-12-06drupal實現(xiàn)在node節(jié)點的評論下面添加內(nèi)容的方法
這篇文章主要為大家介紹了drupal實現(xiàn)在node節(jié)點的評論下面添加內(nèi)容的方法,涉及相關(guān)函數(shù)的修改與hook函數(shù)的使用,具有一定的借鑒價值,需要的朋友可以參考下2014-11-04drupal將Date表單元素月日年的順序改造為年月日的方法
這篇文章主要為大家介紹了drupal將Date表單元素月日年的順序改造為年月日的方法,是很多drupal用戶在進行二次開發(fā)的時候都會遇到的問題,需要的朋友可以參考下2014-11-04- 這篇文章主要為大家介紹了定制Drupal首頁的方法,以實例形式講述了幾種常見的實現(xiàn)方法,非常實用,需要的朋友可以參考下2014-11-05
- 這篇文章主要為大家介紹了Drupal第三方模塊,較為詳細的羅列了drupal常用的第三方模塊及其對應(yīng)的下載地址,對于drupal建站來說具有很好的參考借鑒價值,需要的朋友可以參考下2014-11-06
- 這篇文章主要為大家介紹了drupal6上傳中文文件名附件亂碼問題解決方法,是很多drupal用戶都會遇見的問題,具有很好的參考借鑒價值,需要的朋友可以參考下2014-11-06
drupal函數(shù)node_get_types用法詳解
這篇文章主要為大家介紹了drupal函數(shù)node_get_types用法,針對node_get_types函數(shù)中不同參數(shù)對應(yīng)功能做了簡單描述,對于drupal建站非常具有實用價值,需要的朋友可以參考下2014-11-06

