• Skip to main content

Victor Font Consulting Group, LLC

The DEX Intranet Specialists

Call Us:

+1 919-604-5828

  • Home
  • Care Plans
    • Care Articles
    • Optional Subscriptions
  • Consultations
  • Products
    • Code Snippets
    • Public GitHub Repositories
    • Gist Snippets
    • Pastebin Snippets (Free)
    • Free Plugins
  • FAQs
  • Support
    • Graphic Design
  • Contact
    • Speakers
    • Portfolio
  • Resources
    • Free WordPress Video Training
    • Tutorials
    • Articles
    • Cybersecurity
    • EU Referral Network
You are here: Home / Code Snippet / Formidable Pro Rename Upload File

Formidable Pro Rename Upload File

By Victor M. Font Jr.
December 4, 20156 Comments

Formidable Pro Rename Upload File-public domain image from pixabay.com
As of the release of Formidable Pro V2.02, the process described in this article will no longer work. The Formidable Pro developers abandoned the standard WordPress upload functions in favor of a drag and drop jQuery Ajax uploader. While this is more efficient, it offers significant challenges because the files are uploaded before the form is submitted. When time permits, I'll look into a method for renaming files with this new process. In the meantime, the original article is below and will work with Formidable Pro versions released prior to V2.02.

When Michael Jenson needed help customizing the name of image uploads through a Formidable Pro form, Stephanie Wells of Strategy 11, the author of Formidable Pro, recommended that he contact us for assistance. We do a lot of custom Formidable Pro work and know the product well. Michael's form is located at http://cameraclub.photos/exhibition-upload/. His request:

What I’m looking for is to take all of the fields from this form (except email address) and use them to rename a jpeg image file upon upload. I have several clients who are camera clubs and they are requesting this functionality.

This is a screen print of Michael's form:

Exhibition Upload Form

To clarify the requirement, I responded:

So let’s say I upload an image in category aa, you want the image name to be: victor-font-aa-imagename-open-digital.jpg. Is that correct?

Michael confirmed his requirement and shortly thereafter, I sent the following code to him for testing with instructions to copy it into his child theme's functions.php file.

rename_imagehttps://gist.github.com/vfontjr/199632e7e3d1447c4aeb0510e1b25dec#file-rename_image-php

Michael's response:

This worked awesome!

This Can Work With Most Any Form

The beauty of this code is that with a little modification it could work with any form that uses the WordPress upload process as Formidable Pro does. You would have to determine how your form tool identifies its forms and the naming convention for the fields. The code intercepts and sanitizes the filename just before WordPress saves it. If you need help, you can always reach out to us.

To learn more about PHP's pathinfo() function visit: http://www.w3schools.com/php/func_filesystem_pathinfo.asp
To learn more about the sanitize_file_name filter visit: https://codex.wordpress.org/Function_Reference/sanitize_file_name
  • 1share
  • Facebook0
  • Twitter0
  • Pinterest0
  • LinkedIn1
  • Print
  • SMS0

About Victor M. Font Jr.

Victor M. Font Jr. is an award winning author, entrepreneur, and Senior IT Executive. A Founding Board Member of the North Carolina Executive Roundtable, he has served on the Board of Advisors, of the North Carolina Technology Association, the International Institute of Business Analysis, Association of Information Technology Professionals, Toastmasters International, and the North Carolina Commission for Mental Health, Developmental Disabilities, and Substance Abuse Services. He is author of several books including The Ultimate Guide to the SDLC and Winning With WordPress Basics, and Cybersecurity.

Reader Interactions

VictorFont.com runs on the Genesis Framework

Genesis FrameworkThe Genesis Framework empowers you to quickly and easily build incredible websites with WordPress. Genesis provides the secure and search-engine-optimized foundation that takes WordPress to places you never thought it could go.

Check out the incredible features and the selection of designs. It's that simple—start using Genesis now!

Click here to download The Genesis Guide for Absolute Beginners (PDF - 1.4 MB)

Leave a Reply Cancel reply

Your email address and website will not be published. Required fields are marked *
Posting a comment means that you agree with and accept our Comment & Product Review Policy

Comments

  1. Miles Howard

    June 6, 2016 at 9:04 pm

    Hi Victor! I’m using your beautiful snippet, after update v2.02 this snippet not worked because the entry values aren’t available via POST $_POST[‘item_meta’][x] :(

    Reply
    • Victor M. Font Jr.

      June 8, 2016 at 5:39 am

      Thanks Mike. The team at Strategy 11 has been making so many improvements to Formidable Pro lately that it’s hard to keep up. I’ll look into it figure out how to manage this for the new version.

      Reply
      • Todd

        September 21, 2016 at 10:53 am

        Did you happen to figure out the “fix” for this?

        Reply
        • Victor M. Font Jr.

          September 23, 2016 at 8:16 am

          I have not yet, but I’ve been working with the new upload process on a client’s development site and I understand what it is doing. It does not upload the images to the WordPress media library. In fact, the new process stores uploaded images in a upload/formidable/x/ where x = form id.

          Formidable Pro stores form related items following a data model similar to how WordPress stores posts. That is, all form related items are stored in two tables, frm_items and frm_item_metas. Frm_items stores basic header information for a record and frm_item_metas stores all the related field data. When I looked up the content in the database for a registration’s form profile photo, I was expecting to find the image url, but did not. All I found was a number. The number is the id of a standard WordPress attachment where you can its content in wp_posts and wp_postmeta.

          With all that being said, unless there’s a REST endpoint that allows a post to be edited, or another way to intercept the upload before all the writing to the back end takes place, the process will have to be relegated until after the form is saved. There are 5 places the new file name would need to be applied if we were to follow this through to completion:

          • In wp_posts:
          • post_title
          • post_name
          • guid
        • In wp_postmeta, meta_key = _wp_attached_file:
          • meta value
        • filename in Formidable upload directory
        • This requires quite a bit of work and I’m not sure when I’ll be able to tackle this given my current work load. All I can say is that I know how to do this, I just don’t know when.

          Reply
  2. Stefan

    February 17, 2016 at 8:21 am

    Hi Victor,

    thank you for sharing this!
    How should it look like if upload of multiple files is allowed?
    Best regards,
    Stefan

    Reply
    • Victor M. Font Jr.

      February 18, 2016 at 8:59 am

      Hi Stefan,

      I don’t think it requires any changes for multiple file uploads. This is because we’re filtering the WordPress sanitize_file_name function, which executes for every uploaded file. It should just work as it is.

      Reply

Call: +1 919-604-5828

Send us an E-mail

Accessibility Statement | Affiliate Marketing Disclosure | Capability Statement

Cookie Policy | Comment & Product Review Policy | Privacy Policy | Site Map | Terms & Conditions

Copyright © 2003–2023 Victor M. Font Jr.

Return to top of page