Hi, I have a Course form with a field Trainer-name which is dynamic dropdown [because names can change] from a Trainer_form:
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 );" }
END
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.
Michael.
Please login or Register to submit your answer
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.
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,
Michael.
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: https://formidableforms.com/knowledgebase/dynamic-vs-lookup-fields/.
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: https://formidable-masterminds.com/populate-dropdown-from-sql-query/
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.