user meta shortcode for a default value of file upload

By: Jiyoung Joung | Asked: 02/12/2023
ForumsCategory: Code Helpuser meta shortcode for a default value of file upload
Jiyoung Joung asked 2 years ago
Hi, I add image-user meta field on user registration, and set a default value of file upload field in the other form. Like this:
[user_meta key="image" show="id"]
It is set well, but when I submit the form, the default value of image field has gone, and the validation is failed. How can I succeed that? Should I put some php code sniphet?
Jiyoung Joung replied 2 years ago

I completely solved it thanks to Toyin.

1 Answers
Victor Font answered 2 years ago
Your question is not clear to me. Let me see if I understand. You've added a new field on your user registration form that captures a user's image. You created a user meta field through the Formidable user add-on. You named the user meta field "image-user", is that correct? The form entry value you save to the image-user field is the value of the file upload field. I am assuming you are restricting uploads to 1 per user. Is my understanding correct so far?
Victor Font replied 2 years ago

If I;m right so far, then the problem is the key you are passing to the shortcode. The name of your user meta field is "image–user". The key is the name of the user meta field. You are passing "image" instead of "image-user".

Your use of show="id" is puzzling in the user meta data context. The user_meta shortcode retrieves user meta values from the wp_usermeta table. WordPress stores each field of user meta as key/value pairs. The "key" that you pass through the shortcode is used as a search string for the meta_key field in the wp_usermeta table. The shortcode retrieves that meta_value tied to the meta_key. show="id" does nothing in this case and may even break the shortcode.

If there has been no image uploaded or you are testing the form without having an image uploaded, there is no value for the file upload field. Empty fields are not stored in the database, so there won't be a user meta field for that user.

Jiyoung Joung replied 2 years ago

<p>I'll explain it in detail. I set up the file upload field on the user registration form, and connect user meta to it with key named "portrait". Next I made another form and added the file upload field with default value `[user_meta key=portrait show=id]`. It printed actual media id, but when I hit the submit button, the default value was vanished. What is the mechanism of retrieving the default value of the file upload field?</p>

Victor Font replied 2 years ago

Why do you need a file upload field on the second form?

Jiyoung Joung replied 2 years ago

I can't talk about that because it is a business secret. I only say it is for auto population of the other form.

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