Here is my goal: Take Content profile CCK fields "field_firstname" and "field_lastname" to automagically generate a username.
My approach: To create a custom module using hook_form_altar and a submit handler to auto-append the username and not touch the db scheme.
My problem: I cannot find out how to access the Content Profile additional CCK fields on the registration form. Right now I have a live copy of this.. and I'm using var_dump($form) to look for fields. Live location here.
Here is my module code displaying, any pointers will be greatly appreciated
/**
* Implementation of hook_form_alter().
*
*/
function realname_registration_form_alter(&$form, $form_state, $form_id) {
switch ($form_id) {
case 'user_register':
if (isset($form['account']) && is_array($form['account'])) {
$form['account']['name']['#type'] = 'hidden';
$form['account']['name']['#value'] = user_password();
$form['account']['mail']['#title'] = t('E-mail');
}
else {
$form['name']['#type'] = 'hidden';
$form['name']['#value'] = user_password();
$form['mail']['#title'] = t('E-mail');
}
//$form['#submit'][] = 'realname_registration_name_submit';
print "<pre>";
print_r($form);
print "</pre>";
break;
}
}
/**
* submit handler
*
*/
function realname_registration_name_submit($form, &$form_state) {
}
The values that is submitted in a form, is always located at $form_state['values'][...]. If you have troubles figuring out what they are called, you can print out the $form_state variable and inspect it.
In your case, it looks like this is what you need:
$first_name = $form_state['values']['field_firstname'];
$last_name = $form_state['values']['field_lastname'];
One thing you need to be aware of, is that usernames need to be unique, while names might not be. You also need to expose the username for the new users, so they know how to login.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With