You are here

function profile_form_profile in Drupal 6

Same name and namespace in other branches
  1. 4 modules/profile.module \profile_form_profile()
  2. 5 modules/profile/profile.module \profile_form_profile()
1 call to profile_form_profile()
profile_user in modules/profile/profile.module
Implementation of hook_user().

File

modules/profile/profile.module, line 346
Support for configurable user profiles.

Code

function profile_form_profile($edit, $user, $category, $register = FALSE) {
  $result = _profile_get_fields($category, $register);
  $weight = 1;
  $fields = array();
  while ($field = db_fetch_object($result)) {
    $category = $field->category;
    if (!isset($fields[$category])) {
      $fields[$category] = array(
        '#type' => 'fieldset',
        '#title' => check_plain($category),
        '#weight' => $weight++,
      );
    }
    switch ($field->type) {
      case 'textfield':
      case 'url':
        $fields[$category][$field->name] = array(
          '#type' => 'textfield',
          '#title' => check_plain($field->title),
          '#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
          '#maxlength' => 255,
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        if ($field->autocomplete) {
          $fields[$category][$field->name]['#autocomplete_path'] = "profile/autocomplete/" . $field->fid;
        }
        break;
      case 'textarea':
        $fields[$category][$field->name] = array(
          '#type' => 'textarea',
          '#title' => check_plain($field->title),
          '#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
      case 'list':
        $fields[$category][$field->name] = array(
          '#type' => 'textarea',
          '#title' => check_plain($field->title),
          '#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
      case 'checkbox':
        $fields[$category][$field->name] = array(
          '#type' => 'checkbox',
          '#title' => check_plain($field->title),
          '#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
      case 'selection':
        $options = $field->required ? array() : array(
          '--',
        );
        $lines = split("[\n\r]", $field->options);
        foreach ($lines as $line) {
          if ($line = trim($line)) {
            $options[$line] = $line;
          }
        }
        $fields[$category][$field->name] = array(
          '#type' => 'select',
          '#title' => check_plain($field->title),
          '#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
          '#options' => $options,
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
      case 'date':
        $fields[$category][$field->name] = array(
          '#type' => 'date',
          '#title' => check_plain($field->title),
          '#default_value' => isset($edit[$field->name]) ? $edit[$field->name] : '',
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
    }
  }
  return $fields;
}