[support] More effective use of auto-complete in Profile
Jason Flatt
drupal at oadaeh.net
Wed Mar 7 14:54:13 UTC 2007
On Wednesday March 7 2007 4:42 am, Neil: esl-lounge.com wrote:
> Thanks Gordon,
>
> would it thus be possible to use the hook_form_alter() to get the
> autocomplete to look in say location_towns BUT the value ultimately
> selected by the user is entered into the normal profile_values table? Just
> want to ensure I've understood that correctly.
>
> Scenario:
>
> User A goes to fill out profile "City" field. Types "Sa..." and the
> following values appear:
>
> San Antonio, Texas
> San Francisco, California (both present in our pre-populated location_towns
> table)
>
> User selects San Antonio, Texas but only the value "San Antonio" gets
> entered into the profile_values table. Is that possible?
>
> Neil
>
The short answer is yes.
The medium answer is that you probably also want to use hook_user() to help
with this. In hook_form_alter(), query your database for the cities and
states and use the results to fill your select field's #options array, using
the city table's id as the array's key.
Then in hook_user, probably on the submit op, take the key for the item the
user selected, do another database query on the city table and store that
value in the profile field.
There are actually a couple of different ways you could go about this,
depending on what you ultimately wanted to do. This should at least get you
going in the right direction, and you can work out your details as you come
to them.
http://api.drupal.org/api/5/function/hook_form_alter
http://api.drupal.org/api/5/function/hook_user
http://api.drupal.org/api/5/file/developer/topics/forms_api_reference.html#select
http://api.drupal.org/api/5/group/database
--
Jason Flatt
http://www.oadaeh.net/
Father of Six: http://www.flattfamily.com/ (Joseph, 13; Cramer, 11; Travis,
9; Angela; Harry, 5; and William, 12:04 am, 12-29-2005)
Linux User: http://www.kubuntu.org/
Drupal Fanatic: http://drupal.org/
More information about the support
mailing list