User ID Drop Down List not displayed in Front End

Is there a way to make the user id drop down list that is displayed for administrators to be shown in the front end?

Right now the drop down only displays in the backend when I add an entry there.

 

Thanks.

This is possible but would require some additional code in your theme functions.php or a new plugin. No modification required. You can put this code in a new plugin or your theme functions.php
 

add_filter('frm_setup_new_fields_vars', 'show_user_dropdown', 15, 2);
add_filter('frm_setup_edit_fields_vars', 'show_user_dropdown', 15, 3);
function show_user_dropdown($values, $field, $entry_id=false){
  if($values['type'] == 'user_id' and !is_admin() and current_user_can('administrator') ){
       $values['type'] = 'select';
       $values['options'] = FrmProFieldsHelper::get_user_options();
       $values['use_key'] = true;
       $values['custom_html'] = FrmFieldsHelper::get_default_html('select');
       if(!$entry_id){
          global $user_ID;
          $values['value'] = $user_ID;
      }
  }
return $values;
}

 

For those looking at this post, my final code displays a drop down list of users sorted by last name and then first name in the front end for administrators.  It is a hidden user id field for non-administrators.

Display name is useless for the site because there is a user forum and members are changing their display name to some really weird things.

By still using the user id, we can display a list of the member's forms even if an administrator fills it out for them.

Thank you very much for all your advice, Stephanie.

add_filter('frm_setup_new_fields_vars', 'show_user_dropdown', 15, 2);
add_filter('frm_setup_edit_fields_vars', 'show_user_dropdown', 15, 3);
function show_user_dropdown($values, $field, $entry_id=false){
    if($values['type'] == 'user_id' and !is_admin() and current_user_can('administrator') ){
       $values['type'] = 'select';

       //Replace the following statement which gets a list of ids and
       //display names, sorted by id.

       // $values['options'] = FrmProFieldsHelper::get_user_options();

       // Instead get a list of users, sorted by last name, first name
       global $wpdb; 

       $sql = "SELECT umfirst.user_id as ID, umfirst.meta_value AS ";
       $sql .= "first_name, umlast.meta_value AS last_name FROM ";
       $sql .= "$wpdb->usermeta umfirst, $wpdb->usermeta umlast WHERE ";
       $sql .= "umlast.meta_key = 'last_name' AND umfirst.meta_key = 'first_name' ";
       $sql .= "AND umfirst.user_id = umlast.user_id ORDER BY last_name, first_name";

       $users = $wpdb->get_results($sql);

       foreach($users as $user) //this sets the users up in the format needed for Formidable
       { 
          $options[$user->ID] = $user->last_name . ', ' . $user->first_name; 
       }

       $values['options'] = $options;
       $values['use_key'] = true;
       $values['custom_html'] = FrmFieldsHelper::get_default_html('select');
       if(!$entry_id){
          global $user_ID;
          $values['value'] = $user_ID;
      }

   } 
return $values;
}

This code doesn't actually work well... it changes the field-type to a normal dropdown instead of a 'user field' which can be referenced in the e-mail functions of the form.

Is there any way to modify stephanie's original code to display the full names of the users without breaking the functionality?

 

Anthony

Hi Anthony,

I have actually opened another topic at where we are talking about that.

Topic closed.