I'm trying to do something that I can't quite figure out in Gravity Forms. I feel like I'm nearly there, but just having trouble putting the pieces together!
My form submits to a Custom Post Type. There is a Post Title field, Post Body field, one Custom Taxonomy dropdown box, and two fields that aren't quite standard:
- Category Select dropdown, which is dynamically populated by a parameter in the URL (ie, /newentry/?cat=3 which automatically sets the right category as selected in the dropdown)
- one Image Upload field, where I have the Featured Image box ticked
What I'm trying to do, is change the way the Image Upload field is displayed. For all posts, users will NOT be uploading an image, they will instead be choosing one from a set of images, based on the category they're posting in. I'm using Featured Image as an icon or avatar of sorts for this project. There will be between 8-25 categories, and each category will have around 10-50 icons to choose from, and they will get added to/images replaced on a regular basis (which is why I dismissed creating Conditional Logic fields for each category - it'd take forever and it'd be a hassle to add new icons regularly).
What should happen, is that they pick their category, and get taken to the form. The category is pre-selected in the dropdown based on the URL parameter (this all works perfectly), and then I want to put something in my functions.php that removes the Upload box from the Image Upload field, and replaces it with a bunch of radio buttons, each with an image displayed as the Label, and the URL to the image as the value. When a user then selects an image in the form, it passed back to the Image Upload field, instead of an uploaded image's URL? I think I should be able to do this using gform_field_content?
Now, the images displayed as radio buttons will depend on the category (the cat parameter in the URL), I'm not entirely sure how to grab that parameter inside a function. Originally, I had just decided to make a couple of folders on my server, each named with the category ID, so if the URL is ?cat=3, then PHP simply looks on my server in /images/3/ and loops through all JPGs in it, displaying them all as radio buttons. This seemed the easiest to me, but I'm happy to do it any other way too if that'd be easier - Media Library or something, filtered on the image name perhaps. After tinkering with this for a while, I'm suspecting the Image Upload field, since it uses the Media Library, only passes the image's ID in the library to set it as Featured Image, and not an actual URL. In which case my PHP-folder-looping idea wouldn't work.
I am trying to do this with the Image Upload field, since that has the Set As Featured Image functionality already there. But, if it's easy enough to set a Featured Image through functions.php, then I might be better off trying to replace just a normal Radio Button field instead the Image Upload field? Hope I explained this all OK - I'm open to any ideas on how to best do this! :-)