PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

set value of user meta field with uploaded filename

  1. When a user registers on my site it is possible to upload an image through the file upload field in a GF. I would like to get the filename (so not the full path) in a user meta field called author_image (an plugin for author images).

    The problem is that it's not possible to get the name of the file from the uploadfield because it has a temporary name before getting copied to the correct location.

    How would it be possible to only get the file-name into the author_image user meta field

    Posted 6 years ago on Wednesday January 23, 2013 | Permalink
  2. You would have to retrieve the filename after the file is uploaded and moved, from the entry. Then update the usermeta for the user which was just created.

    The gform_user_registered hook has all the information you need (the user ID and the $entry, which will have the filename):

    http://www.gravityhelp.com/documentation/page/Gform_user_registered

    The function you write will grab the filename from the entry, and update the user meta for that user ID.

    Posted 6 years ago on Wednesday January 23, 2013 | Permalink
  3. ok, but how to grab the filename from the entry ? An example on how to write this function would be appreciated if I wanted the uploaded file-name to be written in user meta author_image. Thanks

    Posted 6 years ago on Wednesday January 23, 2013 | Permalink
  4. I just tested this and you can get the final location of the author image from the file upload field, when you map the feed.

    I added a file upload to my form, then updated the feed to add the custom meta of "author_image" with the value of my file upload field. It's the full path to the image in its final location in the wp-content/uploads/gravity_forms/{form-id-string}/ folder. Screenshot: http://minus.com/ltUL7AoYbIjU2

    Here is the value of file I uploaded (take from the usermeta table): http://gravity.chrishajer.com/wp-content/uploads/gravity_forms/4-677511f74d6823d023e8a1b225314928/2013/01/Screen-Shot-2013-01-10-at-11.57.20-AM.png

    You said you tried that and it was a temporary location?

    Posted 6 years ago on Wednesday January 23, 2013 | Permalink
  5. Sorry but I do not quite understand what you mean by 'map the feed' in relation to the code from gform_user_registered. Does this code execute when a user is registered and if so what do the variables $user_id, $config, $entry, $user_pass do in relation to the filename, in other words how do I use the code to get (only) the name of the uploaded file in the user meta field author_image. I hope you get my drift....

    Posted 6 years ago on Thursday January 24, 2013 | Permalink
  6. After you created the form, you had to go to Forms > User Registration and add a new feed. That is where you would "map" the fields you captured in the form with field in the profile. This screen: http://minus.com/lIAZuOv1RIs9o - See the User Meta section where I added a meta_key of "author_image" and selected the field "Your author image" (the title of the image field in my form) from the drop down. That is what accomplished everything I wrote about in my previous reply.

    I'm ignoring the rest about the gform_user_registered hook for now since I don't think you need it.

    Posted 6 years ago on Thursday January 24, 2013 | Permalink
  7. I thought of that myself and tried it, but it won't create a record author_image in the wp_usermeta table. When I manually add the image, it creates the author_image record without problems.

    Posted 6 years ago on Thursday January 24, 2013 | Permalink
  8. But I did exactly what you wanted to do, as I showed. So what are we doing differently?

    Posted 6 years ago on Friday January 25, 2013 | Permalink
  9. Well I seem to have a different version user registration than you. I don't have the tabs like Edit Feed, User Registration Feeds or Pending Registrations or the Action field at the top of your screen. When I check updates then my Gravity Forms is up to date.

    I found out that when I deactivate the author image plugin, it does create the author_image record in the user meta.

    Posted 6 years ago on Friday January 25, 2013 | Permalink
  10. I used another plugin in combination with the file rename hook i found in the support forum. Thanks for your help.

    Posted 6 years ago on Friday January 25, 2013 | Permalink
  11. Thank you for the update.

    The User Registration Add-on I am using is the beta version. I won't show up as an available update until it is released in final version. That should not affect the functionality you need though: just the appearance of the screen where you map the form fields.

    Posted 6 years ago on Friday January 25, 2013 | Permalink

This topic has been resolved and has been closed to new replies.