嗨,作为 drupal 的新手,请指导如何添加新用户,我知道可以使用带有 user_save 的用户模块,但是如何以及在哪里实现它?
我是否必须在下面的自定义表单的提交处理程序中编写此函数-
function registerme_newform($form, &$form_state)
{
$form = array();
$form['account details'] = array(
'#type' => 'fieldset',
'#title' => t('Account Details'),
'#description' => t('Enter Personal Credentials'),
);
$form['account details']['first name'] = array(
'#type' => 'textfield',
'#title' => t('First Name'),
'#default_value' => t('Be sure of your first name'),
'#attributes' => array(
'onblur' => "if (this.value == '') {this.value = 'Be sure of your first name'}",
'onfocus' => "if (this.value == 'Be sure of your first name') {this.value = ''}"
, ),
);
$form['account details']['last name'] = array(
'#type' => 'textfield',
'#title' => t('Last Name'),
'#default_value' => t('Be sure of your last name'),
'#attributes' => array(
'onblur' => "if (this.value == '') {this.value = 'Be sure of your last name'}",
'onfocus' => "if (this.value == 'Be sure of your last name') {this.value = ''}"
, ), );
$form['account details']['email'] = array(
'#type' => 'textfield',
'#title' => t('E-Mail'),
'#required' => TRUE,
'#default_value' => t('Email acts as username.Dont forget it!'),
'#attributes' => array(
'onblur' => "if (this.value == '') {this.value = 'Email acts as username.Dont forget
it!'}",
'onfocus' => "if (this.value == 'Email acts as username.Dont forget it!')
{this.value = ''}"
, ),
);
$form['account details']['password'] = array(
'#type' => 'password',
'#title' => t('Password'),
'#maxlength' => 60,
'#size' => 60,
'#required' => TRUE,
'#description' => t('Password should be atleast 6 characters long.'),
);
$form['home'] = array(
'#type' => 'fieldset',
'#title' => 'Home Address',
'#description' => t('Enter Personal Residential Credentials')
);
$form['home']['street'] = array(
'#type' => 'textfield',
'#title' => 'Street Address',
);
$form['home']['city'] = array(
'#type' => 'textfield',
'#title' => 'City',
);
$form['work'] = array(
'#type' => 'fieldset',
'#title' => 'Work Address',
'#description' => t('Enter Official Address')
);
$form['work']['street'] = array(
'#type' => 'textfield',
'#title' => 'Street Address',
);
$form['work']['city'] = array(
'#type' => 'textfield',
'#title' => 'City',
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Register Me'),
);
return $form;
}
function registerme_newform_validate(&$form, &$form_state)
{
if($form_state['values']['account details']['first name']=='Be sure of your first
name')
{
form_set_error('first name',t('Please enter your first name'));
}
}
function registerme_newform_submit(&$form, &$form_state)
{
dsm($form_state);
}
还想知道如何在数据库中输入值,我的意思是如何将这些自定义字段添加到数据库中?请指导谢谢。