Posted by IrnBru001 on February 6, 2007 at 4:51pm
Is there any way to set default values in the fields of a profile?
So when people go to make their profile some fields will already have certain information in them. Say a text box will have a the word "default" in there by default or a checkbox should be checked by default.
Any help would be appreciated.
Comments
Check out
Check out hook_profile_alter
http://humanopinion.org
http://humanopinion.org
using hook_profile_alter
see below
I know this is late but
I know this is late but still applies in Drupal 5.x. The answer is to use hook_form_alter for the user_register and user_edit form id's. The hook_profile_alter function is for changing profile fields before they are shown on the page in view mode, not edit or create mode.
Chisholm Technologies, Inc - Custom Software Development since 1999!
www.chisholmtech.com
Chisholm Technologies, Inc - Custom Software Development since 1999!
http://www.chisholmtech.com
default setting for a profile field: 2 kinds of user names...
I want to have a default setting for a profile field. I want it to default to the username. But it needs to be editable by the user.
example: the username is generally "first last" but the profile field will allow another version of the username (that I refer to as "full-name") that could be something more complex and custom "Dr. First x. Last, M.D., Ph.D.")
It's easy to make that profile field but I am not sure how to give it a default setting.
It seems I need to use hook_form_alter but I'm not sure if it will do what I need.
hook_form_alter won't help if field is not in registration form
All of these comments deal with the *interface*, but don't actually set the value unless the user goes to the user settings form. If you've got a profile field that is not in the registration form, and the user never goes to their settings page, the value will not be set.
My Drupal 6 solution, which should be about the same in D4.7 I believe....
Make a module and put code like this in:
<?php/*
* implements hook_user()
*/
function custom_module_user($op, &$edit, &$account, $category = NULL) {
if ($op == 'insert') {
// set defaults for profile items. Profile modules does not support defaults
db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", YOUR_FIELD_ID_NUMBER, $account->uid, YOUR_DEFAULT_VALUE);
}
}
?>
YOUR_FIELD_ID_NUMBER you will have to get by peeking in your profile_fields table in your database, and find the fid of the field you want to set a default for.
YOUR_DEFAULT_VALUE will be the string that is the default value. For the original posters question, that would be '1' for a checked checkbox field.
Note: this is only for the fields not in the registration form. Fields in the registration form should be set using hook_form_alter.
How can i set as default
How can i set as default value the User ID and the Date of Registration? (e.g. 298-22.07.06)
Re: hook_form_alter won't help if field is not in registration
This does not work in Drupal 5
Using hook_profile_alter
I also want to set the default value for profile fields.
Has anyone got any sample code for using hook_profile_alter? I have set up a custom module but can't figure out how to use the hook!
Ben
What for D6?
How can this be fixed in D6?
Thanks,
Gunther