Good Day.
I created a custom registration form in Drupal 7 using FAPI.
I managed to add validation and it works great. Now my problem is when saving it to the database. I can't save my custom data/fields(e.g first Name, Last Name, Birthday, etc) to my db. I don't know how to do it. I followed all the tuts here http://drupal.org/node/1063598 but it seems my blob data is 0 byte. Did i miss something wrong? here is my code. Any replies are much appreciated.
function drupal_onrevue1_form_user_register_submit($form, $form_state){
$edit = array(
'name' => $form_state['values']['name'],
'pass' => $form_state['values']['current_pass'],
'field_first_name' => array(LANGUAGE_NONE => array(array('value' => $form_state['values']['field_first_name']))),
'field_last_name' => array(LANGUAGE_NONE => array(array('value' => $form_state['values']['field_last_name']))),
'field_middle_name' => array(LANGUAGE_NONE => array(array('value' => $form_state['values']['field_middle_name']))),
'field_year_select' => array(LANGUAGE_NONE => array(array('value' => $form_state['values']['field_year_select']))),
'field_month_select' => array(LANGUAGE_NONE => array(array('value' => $form_state['values']['field_month_select']))),
'field_date_select' => array(LANGUAGE_NONE => array(array('value' => $form_state['values']['field_date_select']))),
'field_gender_select' => array(LANGUAGE_NONE => array(array('value' => $form_state['values']['field_gender_select']))),
'mail' => $form_state['values']['field_mail'],
'init' => $form_state['values']['field_mail'],
'status' => 1,
'access' => REQUEST_TIME,
);
user_save(drupal_anonymous_user(), $edit);
}
function form_user_register($form_state) {
$form['#validate'][] = 'drupal_onrevue1_validate_register_form';
$form['#submit'][] = 'drupal_onrevue1_form_user_register_submit';
$month = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October','November', 'December');
for($i=1; $i < 32; $i++){
$date[] = $i;
}
for($i=date("Y"); $i > 1900; $i--){
$year[] = $i;
}
$form['field_first_name'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#attributes' => array('class' => array('reg_input _con'), 'placeholder' =>'First Name'),
);
$form['field_last_name'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#attributes' => array('class' => array('reg_input _con'), 'placeholder' =>'Last Name'),
);
$form['field_middle_name'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#maxlength' => '2',
'#attributes' => array('class' => array('reg_input1 _con'), 'placeholder' =>'M.I'),
);
$form['field_gender_select'] = array(
'#type' => 'select',
'#attributes' => array('class' => array('drop_filed')),
'#required' => TRUE,
'#empty_option' => '- Gender -',
'#options' => array(
1 => t('Male'),
2 => t('Female'),
),
);
$form['field_month_select'] = array(
'#type' => 'select',
'#attributes' => array('class' => array('drop_filed _con')),
'#required' => TRUE,
'#empty_option' => '- Month -',
'#options' => $month,
);
$form['field_date_select'] = array(
'#type' => 'select',
'#required' => TRUE,
'#empty_option' => '- Date -',
'#attributes' => array('class' => array('drop_filed1 _con'), 'style'=>'width:70px;'),
'#options' => $date
);
$form['field_year_select'] = array(
'#type' => 'select',
'#required' => TRUE,
'#empty_option' => '- Year -',
'#attributes' => array('class' => array('drop_filed1'), 'style'=>'width:80px;'),
'#options' => $year,
);
$form['field_mail'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#attributes' => array('class' => array('reg_input _3 '), 'placeholder' =>'Email Address'),
);
$form['name'] = array(
'#type' => 'textfield',
'#required' => TRUE,
'#attributes' => array('class' => array('reg_input _3'), 'placeholder' =>'Username')
);
$form['current_pass'] = array(
'#type' => 'password',
'#required' => TRUE,
'#attributes' => array('class' => array('reg_input _3 '), 'placeholder' =>'Password'),
);
$form['field_repassword'] = array(
'#type' => 'password',
'#required' => TRUE,
'#attributes' => array('class' => array('reg_input _3 '), 'placeholder' =>'Re-type Password'),
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#attributes' => array('class' => array("btn btn-medium btn-success"), 'style'=>'width:60px'),
);
return $form;
}