I have created a profile field for users to indicate who invited them to the site. I have typed in a few demo names in the Selection Options field, but I would prefer to return a dynamic list of all active users. I don't want to have to administer this every time a user joins or changes their user name. I have read every forum post that seemed relevant, tried every combination of punctuation known to man, but I just can't figure it out. I do not want to hack into (read: screw up) the profiles module. Is there a way to enter something into the Selection Options field that will return a list of user names?

Comments

titouille’s picture

Hello,

Have you find a solution for your problem ? because I'd like to do the same thing (dynamic select in profile edition mode) but don't find any thread related to...

Thanks in advance.

alan d.’s picture

Before trying, make sure that there is not already a custom module already for this... you never know...

Anyway, the profile module is very limited in features c/f advanced modules like CCK. There are no hooks to define new elements, so you need a work around by manually hooking into the form using hook_form_alter

While I haven't the time at the moment to actually code it for you, I've used the following steps to alter elements:

1) Define a text field / select list in the profile module

2) Using form alter hook, modify the form field you created above.

<?php
/**
 * Implementation of hook_form_alter().
 */
function newsmark_form_alter(&$form, $form_state, $form_id) {
  //dpm($form_id);
  switch($form_id) {
    case 'user_register':
    case 'user_profile_form':
      // the two forms of interest
      newsmark_profile_selection_options($form, $form_state, $form_id);
      break;
  }
}
?>

I'd use a select list populated from site users, username => username for the options

Learning how to modify forms by the FAPI is not an easy task but well worth it.

3) Thats it, unless you want to get really fancy (Eg: defining a uid => username select list and custom theming all relevant profile field displays), this will ensure that the data does not become stale if the user updates their username.

I would not use user_hook unless you want to manually handle form submission values yourself.

Also check out http://drupal.org/project/usernode, haven't tried it but it could provide a non-code solution, CCK, user reference required to expand the "usernode" content type.


Alan Davison