Creating a form for editing WP profiles, chosen by a dropdown list

By: Mike MacDonald | Asked: 04/29/2023
ForumsCategory: How-toCreating a form for editing WP profiles, chosen by a dropdown list
Mike MacDonald asked 2 years ago
Need to create a form that does the following:
  • Can pick a list of users from a selected user role and edit profile fields 
  • Profile fields can be either from user or user meta tables 
Can anyone help? or point us in the right direction? Thanks 
Mike 
2 Answers
Victor Font answered 2 years ago
Picking a list via user role is custom work, but is possible using custom SQL and Formidable hooks to populate your search record. Everything else is done with the User Registration Add-on.
Mike MacDonald answered 2 years ago
Appreciate the answer Victor -  Thanks very much Could you please comment on this code? add_filter('frm_setup_new_fields_vars', 'populate_dropdown_with_users_on_form_load', 10, 2);
function populate_dropdown_with_users_on_form_load($values, $field) {
    // Check if the field is the dropdown field you want to populate
    if ($field->type == 'select' && $field->id == 'dropdown_field_id') {
        // Get all user IDs and names
        $users = get_users();
        
        // Prepare choices array
        $choices = array();
        
        foreach ($users as $user) {
            $choices[$user->ID] = $user->display_name;
        }
        
        // Modify the field configuration with the updated choices
        $values['field_options']['choices'] = $choices;
    } Is this getting anything like it needs to be? Thanks for any tips or references
Kind regards 
Mike 
 
 
Victor Font replied 2 years ago

I suggest you use the Kint debugger to see the actual values in the $values array and $field object. $field->id == 'dropdown_field_id' will never be true. 'dropdown_field_id', if anything, is a field key. Field ids are always numeric values. You asked about selecting users by user role. This snippet doesn't address the role.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right