hello,
lately I ave been searching to find a way to load a dynamic list into a list option field.
I found the Webform module which allows one to create a webform in which we can add new fields. I also found a way to load a dynamic list option value by hacking the webform module. I found it on the following website: http://www.designhammer.com/news/providing-dynamic-select-options-to-web...
However this works only if you are creating your own webform along with the fields.
What I want is, for each user I create I would like to assign a department , this department list should be retrieved from the database.
What I managed to do is to create the list option field using the profile module. however for this list option field I want to be able to write a query to retrieve data from database.
anyone with a clue ?
Thank you !
Comments
I found the Solution !
After you do the following modifications to the profile module you will have the following:
- have an additional field type which is 'Dynamic list selection'
-when you select this option you will be able instead of writing statically your values(as for the list selection) into the options text area, you will rather write you own query into this text area.
an example query(write it within the option text area): SELECT explanation FROM {profile_fields}
NB: the select option field takes only values only if the type of column is 'text', in our case explanation is of type text.
if you rather write: SELECT fid FROM {profile_fields}
you will have empty fields within the select list, since fid is of type int
I will keep it for you to solve this matter, and customize it to your needs.
here you go, follow these steps:
1- enable the 'Profile' module
2- in 'profile.module' file add the following code:
(line 41)
line(264)
line(413)
line(567)
3- in 'profile.admin.inc' add the following code:
line(250)
4- in profile.pages.inc :
line (48)
line(73):
thats it hope I did not miss anything !
you surely don't want to do it that way...
any time you get an core update, you will over write your changes... better to try and use the hook method to add in your changes, in which case, you won't have to constantly re-implement them.
I achieved this with hook_form_alter()
Bartezz has a nice example here that I used to create database driven lists on the profile page. You need to create a simple module but it super easy if you follow these steps.