« How to redirect user upon first login in Drupal | Main | Overhaul the beta site »

November 29, 2010

CCK Default Value Snippets in Drupal

Here are php snippets I used to set default values for logged-in users who are going to apply for housing.

Need to deal with
Date of Birth (See this post for ideas on how to deal with this)

###########################################
PATTERN USED FOR CONTENT PROFILE FIELDS (role, first name, middle name, last name, gender, umid, address, city, state, country, perm_address, perm_city, perm_state, perm_country, perm_zip, phone, work_phone, emerg_fname, emerg_lname, emerg_phone1, zipcode)

global $user;
$default = content_profile_load('person', $user->uid);
if($user->uid!=1 && user_is_logged_in()){
if (!empty($default->field_person_emerg_email) ) {
$emerg_email = $default->field_person_emerg_email[0]['value'];
return array(
0 => array('value' => $emerg_email)
);
}
}
else return array();


###########################################
PATTERN USED FOR NODE REFERENCE FIELDS IN CONTENT PROFILE (institution)

global $user;
$default = content_profile_load('person', $user->uid);
if($user->uid!=1 && user_is_logged_in()){
if (!empty($default->field_person_institution_ref) ) {
$institution_ref = $default->field_person_institution_ref[0]['nid'];
return array(
0 => array('nid' => $institution_ref)
);
}
}
else return array();


#################################################
PHP USED FOR EMAIL DEFAULT

global $user;
$default = $user->mail;
if($user->uid!=1 && user_is_logged_in()){
if (!empty($default) ) {
return array(
0 => array('email' => $default)
);
}
}
else return array();

Posted by kkwaiser at November 29, 2010 03:58 PM

Comments

Login to leave a comment. Create a new account.