diff options
Diffstat (limited to 'modules/profile.module')
-rw-r--r-- | modules/profile.module | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/modules/profile.module b/modules/profile.module index 720385e69..b269c2688 100644 --- a/modules/profile.module +++ b/modules/profile.module @@ -79,6 +79,10 @@ function profile_menu($may_cache) { 'title' => t('delete field'), 'callback' => 'profile_field_delete', 'type' => MENU_CALLBACK); + $items[] = array('path' => 'profile/autocomplete', 'title' => t('profile autocomplete'), + 'callback' => 'profile_autocomplete', + 'access' => 1, + 'type' => MENU_CALLBACK); } return $items; @@ -271,6 +275,10 @@ Unless you know what you are doing, it is highly recommended that you prefix the '#description' => t('To enable browsing this field by value, enter a title for the resulting page. An example page title is "People who are employed". This is only applicable for a public field.'), ); } + $form['fields']['autocomplete'] = array('#type' => 'checkbox', + '#title' => t('Form will auto-complete while user is typing.'), + '#default_value' => $edit['autocomplete'], + ); $form['fields']['required'] = array('#type' => 'checkbox', '#title' => t('The user must enter a value.'), '#default_value' => $edit['required'], @@ -326,13 +334,13 @@ function profile_field_form_validate($form_id, $form_values) { */ function profile_field_form_submit($form_id, $form_values) { if (!isset($form_values['fid'])) { - db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s')", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['type'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['options'], $form_values['page']); + db_query("INSERT INTO {profile_fields} (title, name, explanation, category, type, weight, required, register, visibility, autocomplete, options, page) VALUES ('%s', '%s', '%s', '%s', '%s', %d, %d, %d, %d, %d, '%s', '%s')", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['type'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['autocomplete'], $form_values['options'], $form_values['page']); drupal_set_message(t('The field has been created.')); watchdog('profile', t('Profile field %field added under category %category.', array('%field' => theme('placeholder', $form_values['title']), '%category' => theme('placeholder', $form_values['category']))), WATCHDOG_NOTICE, l(t('view'), 'admin/settings/profile')); } else { - db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, options = '%s', page = '%s' WHERE fid = %d", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['options'], $form_values['page'], $form_values['fid']); + db_query("UPDATE {profile_fields} SET title = '%s', name = '%s', explanation = '%s', category = '%s', weight = %d, required = %d, register = %d, visibility = %d, autocomplete = %d, options = '%s', page = '%s' WHERE fid = %d", $form_values['title'], $form_values['name'], $form_values['explanation'], $form_values['category'], $form_values['weight'], $form_values['required'], $form_values['register'], $form_values['visibility'], $form_values['autocomplete'], $form_values['options'], $form_values['page'], $form_values['fid']); drupal_set_message(t('The field has been updated.')); } @@ -640,6 +648,9 @@ function profile_form_profile($edit, $user, $category) { '#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', @@ -695,6 +706,22 @@ function profile_form_profile($edit, $user, $category) { } /** + * Callback to allow autocomplete of profile text fields. + */ +function profile_autocomplete($field, $string) { + if (db_result(db_query("SELECT COUNT(*) FROM {profile_fields} WHERE fid = %d AND autocomplete = 1", $field))) { + $matches = array(); + $result = db_query_range("SELECT value FROM {profile_values} WHERE fid = %d AND LOWER(value) LIKE LOWER('%s%%') GROUP BY value ORDER BY value ASC", $field, $string, 0, 10); + while ($data = db_fetch_object($result)) { + $matches[$data->value] = check_plain($data->value); + } + + print drupal_to_js($matches); + } + exit(); +} + +/** * Helper function: update an array of user fields by calling profile_view_field */ function _profile_update_user_fields($fields, $account) { |