« Differences between $Drush cron and web cron | Main | Customizing User Registration page »

September 16, 2010

Setting default values for CCK values based upon Content Profile fields

One nice thing about Content Profile is, if you've marked a content type as part of the profile and set it as part of the user registration process, once a person registers, you can easily bring that data into cck fields as the default value. Here, I created a text field (name) in a content type and placed this code into the default value field at admin/content/node-type/[your content type]/fields/field_name

global $user;
$default = content_profile_load('person', $user->uid);
if($user->uid!=1){
  if (!empty($default->field_person_first_name) || !empty($default-> field_person_last_name)) {
    $fullname = $default->field_person_first_name[0]['value'] . " " . $default->field_person_last_name[0]['value'];
    return array(
        0 => array('value' => $fullname)
    );
  }
}
else return array();

If this makes sense...my thought right now is that once a person registers, they would be redirected to a new page (based upon their role) that allows them to apply for housing and or complete the research portion of the project. These forms (the housing form in particular) could be pre-populated with the code above. This is important because a single person will often submit several housing application forms in a given year.

I'm not sure yet how to deal with research projects though. It cannot really be part of the profile because multiple people will share the same project and not everyone has a project. That said, the creation of a research project needs to be mandatory for certain people (e.g., Investigators) so how can that be enforced (programmatically)?

This is probably a good time to reference this blog post: Building forms with cck, actions and workflow

Posted by kkwaiser at September 16, 2010 01:17 PM

Comments

Login to leave a comment. Create a new account.