Index: profile.module =================================================================== RCS file: /usr/local/tapestry/cvsroot//drupal51/modules/profile/profile.module,v retrieving revision 1.2 diff -u -r1.2 profile.module --- profile.module 29 Jul 2007 11:27:05 -0000 1.2 +++ profile.module 20 Sep 2007 00:11:11 -0000 @@ -251,7 +251,7 @@ '#default_value' => $edit['explanation'], '#description' => t('An optional explanation to go with the new field. The explanation will be shown to the user.'), ); - if ($type == 'selection') { + if ($type == 'selection' || $type == 'selectother') { $form['fields']['options'] = array('#type' => 'textarea', '#title' => t('Selection options'), '#default_value' => $edit['options'], @@ -525,16 +525,25 @@ } function profile_save_profile(&$edit, &$user, $category) { + $result = _profile_get_fields($category); + while ($field = db_fetch_object($result)) { if (_profile_field_serialize($field->type)) { $edit[$field->name] = serialize($edit[$field->name]); } + if ($field->type == 'selectother'){ + if ($edit[$field->name] == 'Other...'){ + $edit[$field->name] .= '-'.$edit[$field->name.'_other']; + $edit[$field->name.'_other'] == ''; + } + } db_query("DELETE FROM {profile_values} WHERE fid = %d AND uid = %d", $field->fid, $user->uid); db_query("INSERT INTO {profile_values} (fid, uid, value) VALUES (%d, %d, '%s')", $field->fid, $user->uid, $edit[$field->name]); // Mark field as handled (prevents saving to user->data). $edit[$field->name] = NULL; } + } function profile_view_field($user, $field) { @@ -691,8 +700,54 @@ '#required' => $field->required, ); break; + case 'selectother': + $options = $field->required ? array() : array('--'); + $lines = split("[,\n\r]", $field->options); + foreach ($lines as $line) { + if ($line = trim($line)) { + $options[$line] = $line; + } + } + $options['Other...'] = 'Other...'; + + $value = split('-', $edit[$field->name]); + + $fields[$category][$field->name] = array ('#weight' => 10); + $fields[$category][$field->name][$field->name] = array('#type' => 'select', + '#title' => check_plain($field->title), + '#default_value' => $value[0], + '#options' => $options, + '#description' => _profile_form_explanation($field), + '#required' => $field->required, + '#attributes' => array('onChange' => 'other(this, "'.$field->name . '_other")') + ); + $fields[$category][$field->name]['1'] = array( '#value' => '