Allow update of USERID to any value from front end

By: Michael Tidbury | Asked: 02/14/2023
ForumsCategory: Code SnippetsAllow update of USERID to any value from front end
Michael Tidbury asked 1 year ago

Hi, I have a Course form with a field Trainer-name which is dynamic dropdown [because names can change] from a Trainer_form:

  • Trainer-name <-- Dropdown on screen.
  • Trainer-USERID <-- This is the Wordpress USERID for the Trainer copied from the wp user file.
  • and other details.

I want only the Trainer from the particular Course entry to be able to see it. I need the entry-USERID set to the Trainer-USERID - not the 'current_user'.

Simplified PSEUDOCODE:

On create/update take the Trainer-name from the screen

IF there is one entered {

Select Trainer-USERID from Trainer_form where Trainer-name equals the value from the screen.

Set entry-USERID to Trainer-USERID -> "FrmEntryMeta::update_entry_meta( $entry_id, 757, null, $TrainerUserID );" }


I do not know how to do the italic bold statement; everything else is fine.

I do not want to expose the entry-USERID field on the front end and want to keep the system separate from the wp user table.

Any help would be appreciated.


Victor Font replied 1 year ago

For anyone to have a userid, they must have a record in the wp_user table. You would have to get the trainer userid from the wp_users table to pass it as a parameter to your view. It makes no sense to me why you would change a userid for any purpose.

Michael Tidbury replied 1 year ago

Thank you for your response.

For me it makes perfect sense - the reason I want to change the USERID on the Course entry is that the 'owner' of the entry is not the person who creates it (a central coordinator) but the person to whom the course has been allocated (the Trainer).

In this way the 'normal' Formidable security applies as if the Trainer had created the Course entry and it works very well indeed. It has been in place for quite some time but I have been manually changing the course entry USERID to the Trainer's USERID (which I took from the wp_users table) because there are actually very few Course entries.

I simply wanted to simplify the process so that when the Course entry is assigned by the coordinator, i.e. ownership is passed to the Trainer, I did not have to go and make the change manually.

I have tried to avoid accessing the wp_user table directly for fear of screwing it up.

If I have a dynamic lookup field in a form how do I pull TWO fields from the Table being looked up in: one the Trainer name (to put into the form and display) and the other, the Trainer USERID, with which to automatically update the entry USERID?

Any thoughts would be appreciated, thanks,


Victor Font replied 1 year ago

Now that you've explained it, it does make perfect sense. You won't screw up the user table by just querying its data. Normally, you wouldn't do that anyway. You would just use WordPress functions to retrieve the user details you want by passing parameters.

Formidable has specific design functionality for Dynamic vs. Lookup vs. Standard Dropdown fields. There are significant distinctions and understanding them will save heartache and redesign later. To learn more, please see this Formidable Knowledgebase article:

Back to your question about separate values in a "dynamic" field. I wouldn't use either the Dynamic or Lookup field to satisfy this request. I would use a standard dropdown field set for separate values, then use the frm_setup_new_fields_vars and frm_setup_edit_fields_vars filters to populate your custom data.

This might help:

The article shows how to populate a single value, but I believe there's an example in the Knowledgebase that shows how to populate separate values. I haven't been able to locate it at present.

2 Answers
Walter JonesWalter Jones answered 1 year ago
So I do something similar where I have users to write reports but sometimes I want to assign the report to someone else other than the original author.  I used this code snippet that turns the userid field into a drop-down where I can basically “assign” any entry to any user.  It might work in your case…
Michael Tidbury answered 1 year ago
Thank you both for your help. I have gone with a combination of both. I have used Add User Dropdown from because it is almost exactly what I need. I found it following up your suggestions. I will now need to get the results to update the entry-USERID. All the best, Michael.

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