drupal用户注册时,默认只需要提供用户名和密码即可。很多时候这个是完全不够用的,我们还希望在用户注册时记录更多的信息,比如生日,性别和自我介绍等等。这个时候就需要hook_user了:
function yourmodulename_user($op, &$edit, &$user, $category = NULL) {
switch ($op) {
//注册时扩展的字段
case ‘register’:
$fields[‘personal_profile’][‘custom1’] = array(
‘#title’ => t(‘自定义字段1’),
‘#type’ => ‘textfield’,
);
$fields[‘personal_profile’][‘custom2’] = array(
‘#title’ => t(‘自定义字段2’),
‘#type’ => ‘textfield’,
);
return $fields;
//参数验证
case ‘validate’:
print_r($fields);
if ($fields[‘personal_profile’][‘custom1’] == ”) {
form_set_error(‘custom1’, t(‘自定义字段1不能为空! ‘));
}
if ($fields[‘personal_profile’][‘custom2’] == ”) {
form_set_error(‘custom2’, t(‘自定义字段2不能为空! ‘));
}
return;
}
}
Tags: drupal