Drupal 4.6.5

Hi there,

I have added a number of custom user profile fields using the Profile module. It looks a bit untidy, so I'm trying to modify the layout of the registration page. I think I've found the correct section of code in the profile.module file, and as a test I wanted to modify the width of a text field - because it's way too wide. However, in the case statement, there is nothing next to the case 'textfield' entry (see below). I've searched for the form_textfield that would generate custom single-line textfields but cannot find it - am I missing something here?

function profile_form_profile($edit, $user, $category) {

  if (($_GET['q'] == 'user/register') ? 1 : 0) {
    $result = db_query('SELECT * FROM {profile_fields} WHERE register = 1 ORDER BY category, weight');
  }
  else {
    $result = db_query("SELECT * FROM {profile_fields} WHERE LOWER(category) = LOWER('%s') ORDER BY weight", $category);
    // We use LOWER('%s') instead of PHP's strtolower() to avoid UTF-8 conversion issues.
  }

  $fields = array();
  while ($field = db_fetch_object($result)) {
    $category = $field->category;
    switch ($field->type) {
      case 'textfield':
      case 'url':
        $fields[$category] .= form_textfield(check_plain($field->title), $field->name, $edit[$field->name], 70, 255, _profile_form_explanation($field), NULL, $field->required);
        break;
      case 'textarea':
        $fields[$category] .= form_textarea(check_plain($field->title), $field->name, $edit[$field->name], 70, 5, _profile_form_explanation($field), NULL, $field->required);
        break;
      case 'list':
        $fields[$category] .= form_textarea(check_plain($field->title), $field->name, $edit[$field->name], 70, 5, _profile_form_explanation($field), NULL, $field->required);
        break;
      case 'checkbox':
        $fields[$category] .= form_checkbox(check_plain($field->title), $field->name, 1, $edit[$field->name], _profile_form_explanation($field), NULL, $field->required);
        break;
      case 'selection':
        $options = array('--');
        $lines = split("[,\n\r]", $field->options);
        foreach ($lines as $line) {
          if ($line = trim($line)) {
            $options[$line] = $line;
          }
        }

        $fields[$category] .= form_select(check_plain($field->title), $field->name, $edit[$field->name], $options, _profile_form_explanation($field), 0, 0, $field->required);
        break;
      case 'date':
        $fields[$category] .= _profile_date_field($field, $edit);
        break;
    }
  }

  if ($fields) {
    foreach ($fields as $category => $data) {
      $output[] = array('title' => $category, 'data' => $data);
    }
    return $output;
  }
}

Comments

heine’s picture

If there's no break before the next case, control falls through (see http://www.php.net/switch). That means that case 'textfield' falls throught and executes code in case 'url', where a textfield is defined.

    switch ($field->type) {
      case 'textfield':
         // No break; falls through
      case 'url':
        $fields[$category] .= form_textfield(check_plain($field->title), $field->name, $edit[$field->name], 70, 255, _profile_form_explanation($field), NULL, $field->required);
        break;
      case 'textarea':
        $fields[$category] .= form_textarea(check_plain($field->title), $field->name, $edit[$field->name], 70, 5, _profile_form_explanation($field), NULL, $field->required);
        break;

--
The Manual | Troubleshooting FAQ | Tips for posting | Make Backups! | Consider creating a Test site.

stretchwickster’s picture

I see - thanks for the explanation. However, any changes I do make to the length of the quoted form_textfield function are not reflected on screen. Am I in the right module and function for tinkering with the layout of the registration page?