The goal of this formidable pro form requires three non-standard things to occur. I've written a custom plug-in with code that accomplishes two of the three goals, but I am unable to get the third requirement to work.

REQUIREMENT #1: Make the normally hidden UserID field visible to all users of the form, even if they are not logged in to the site. THIS WORKS!

REQUIREMENT #2: Filter the contents of this drop-down field so that it only displays a list of users whose role=author, instead of ALL users. THIS WORKS!

REQUIREMENT #3: Once the user makes a selection, that value is passed to the UserID variable, such that once the form is submitted, it is treated as if the User selected from the drop-down was the author of the form. HERE IS WHERE I NEED HELP!

Here is the code that works for #1 and #2, but fails at #3.

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( $field->id == 898 ){
$values['type'] = 'select';
$values['use_key'] = true;
$values['custom_html'] = FrmFieldsHelper::get_default_html('select');
$wp_user_search = new WP_User_Query( array( 'role' => 'author', 'fields' => array('user_login', 'ID') ) );
$authors = $wp_user_search->get_results();
$values['options'] = array();
foreach ($authors as $a) {
$values['options'][$a->ID] = $a->user_login; } }
return $values; }

Notice that nothing has been assigned to the variable $values['value']. Every attempt I've made to assign something (i.e. ID) to that variable fails to work.

Also, if I change this line:

$values['options'][$a->ID] = $a->user_login;


$values['options'][$a->ID] = $a->ID;

Then Requirement #3 works, but #2 fails in part. The User ID WILL be correctly passed to the $values['value'] variable, and the submission will appear to have been authored by the selected user from the drop-down. However, the drop-down will display a list of integers (ID) rather than the user names (user_login).

Any help would be greatly appreciated!

closed as off-topic by Howdy_McGee Sep 15 '17 at 22:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.