Create a entry for specific user using API

By: Michael Clark | Asked: 05/09/2023
ForumsCategory: How-toCreate a entry for specific user using API
Michael ClarkMichael Clark asked 2 years ago
I have a entries in a form, each associated with the user that submits the entries. That form gets updated by an administrative user. This update triggers the API action to create a new entry in another form using the POST method. The User ID field is mapped from, but it the User ID field in the second form's entries is blank. I tested by mapping the User ID field in form A to a text field in form B, and that works. Anyone have a workaround for making sure the User ID filed in the second form gets the value from the User ID in the first form?
1 Answers
Victor Font answered 2 years ago
Did you add the user id field to the target form? Formidable stores the WordPress user id automatically in the user_id field of the frm_items table. This is the user ID of the logged in user creating the entry. The frm_items table serves as an entry header record. Other than the entry name, there's not much other useful information unless you're writing custom SQL queries or debugging code. All form entry data is stored in the frm_item_metas table. I'm going to continue this thinking in the comment to follow. HTML is messed up on this site and the answer fields don't format properly.
Victor Font replied 2 years ago

As a standard practice, we include the drag and drop user_id field on every form we build. Having the data in the form's metadata makes user id related queries easier.

I just ran an experiment on my dev server to see what Formidable does with user_id values. This is the experiment:

1. Added user_id to catchall play form.
2. Previewed form in theme
3. Opened browser inspection tool to examine user id field's HTML. The hidden user id field is cryptically displayed. You cannot know this is a user id variable without the field id number. Look for name="item_meta[1462]" where the 1462 is the field id of your form's user_id field.

4. Change the value="1" data-frmval="1" to different numbers
5. Submit entry
6. Examine frm_items and frm_item_metas in PHPMyAdmin and compare user id fields.

Results:

In each of three experiments testing permutations of the value and data-frmval combination, the outcome was the same. The user_id field in frm_items and the user_id meta field are identical. Formidable used the fake id number submitted as a test. There is no WordPress user id corresponding to the number submitted in the test. Formidable does not appear to validate the user id against the WordPress user table.

Conclusion:

There should be nothing standing in the way of the user id field in Form 2 not getting populated. Maybe there's something wrong with your mapping. All I can suggest is that you may need to consider hiring a developer to take a look. The problem seems to be with your system, not the user id field. Torubleshooting this is beyond what we can do as volunteers here. To find a developer, please visit https://formidable-masterminds.com/developers-directory/

Victor Font replied 2 years ago

Something else to try, are the two forms in the same Formidable instance or in different servers? If they are in the same instance and the same admin user has access to both forms, set the default value to [user_id] in the second form. If you want the user id to be something other than the same admin user, talk to a dev.

Michael ClarkMichael Clark replied 2 years ago

Thanks for your comments, Victor. I've done more testing and found that I can map the field in Form 1 to a text field, and a hidden field in Form 2 and the values are indeed populated the same.

My issue is that I need to create a single entry View where User ID = current_user, based on Form 2.

By way of workaround, I thought that I may be able to use the nested Views method with Form 2 as the detail, and using some other user-unique value like email address as the parameter passed in from Form 1, but since there's *always* an email address, it'll always return the latest entry, but not one unique to the current user.

Since the Value *is* coming through in a hidden field, I wish there was someway to filter the View where User ID = [key of hidden field]. That'd be a decent workaround. What's weird, is this had worked in lots of other things, just not this one. And of course, it's a critical workflow enhancement. 🙂

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