profile_form_profile

Versions
4.6 – 4.7
profile_form_profile($edit, $user, $category)
5 – 6
profile_form_profile($edit, $user, $category, $register = FALSE)

Code

modules/profile.module, line 606

<?php
function profile_form_profile($edit, $user, $category) {
  if (arg(0) == 'user' && arg(1) == 'register') {
    $result = db_query('SELECT * FROM {profile_fields} WHERE visibility != %d AND register = 1 ORDER BY category, weight', PROFILE_HIDDEN);
  }
  elseif (arg(0) == 'admin' && arg(1) == 'user' && arg(2) == 'create') {
    $result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
  }
  elseif (user_access('administer users')) {
    $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = LOWER('%s') ORDER BY weight", $category);
  }
  else {
    $result = db_query("SELECT * FROM {profile_fields} WHERE visibility != %d AND LOWER(category) = LOWER('%s') ORDER BY weight", PROFILE_HIDDEN, $category);
    // Use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues.
  }

  $w = 1;
  while ($field = db_fetch_object($result)) {
    $category = $field->category;
    if (!isset($fields[$category])) {
      $fields[$category] = array('#type' => 'fieldset', '#title' => check_plain($category), '#weight' => $w++);
    }
    switch ($field->type) {
      case 'textfield':
      case 'url':
        $fields[$category][$field->name] = array('#type' => 'textfield',
          '#title' => check_plain($field->title),
          '#default_value' => $edit[$field->name],
          '#maxlength' => 255,
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
      case 'textarea':
        $fields[$category][$field->name] = array('#type' => 'textarea',
          '#title' => check_plain($field->title),
          '#default_value' => $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' => $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' => $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' => $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' => $edit[$field->name],
          '#description' => _profile_form_explanation($field),
          '#required' => $field->required,
        );
        break;
    }
  }
  return $fields;
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.