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' => '
'); + $fields[$category][$field->name][$field->name.'_other'] = array( '#type' => 'textfield', + '#title' => t('More information on "other".'), + '#description' => t('You selected "other" above. Please tell us more.'), + '#default_value' => $value[1] + ); + $fields[$category][$field->name]['10'] = array( '#value' => "
"); + $fields[$category][$field->name]['11'] = array( '#value' => + ''); + break; + } } + return $fields; } @@ -731,6 +786,10 @@ form_set_error($field->name, t('The value provided for %field is not a valid URL.', array('%field' => $field->title))); } } + if ($field->type == 'selectother') { + if ($edit[$field->name] == 'Other...' && empty($edit[$field->name .'_other'])) + form_set_error($field->name .'_other', t('You selected "other". Please describe.')); + } } else if ($field->required && !user_access('administer users')) { form_set_error($field->name, t('The field %field is required.', array('%field' => $field->title))); @@ -790,7 +849,9 @@ 'selection' => t('list selection'), 'list' => t('freeform list'), 'url' => t('URL'), - 'date' => t('date')); + 'date' => t('date'), + 'selectother' => t('list selection with other')); + return isset($type) ? $types[$type] : $types; }