drupal自定义用户注册参数

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;

 }
}

 

发表评论

邮箱地址不会被公开。 必填项已用*标注

机器人检查 *

分享我的最新文章标题到这里

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据