Skip Navigation

[Resolved] How to upload multiple images with Gravity Forms – Part 2

This support ticket is created 3 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 3 replies, has 2 voices.

Last updated by Luo Yang 3 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#2010179

Tell us what you are trying to do? Upload multiple images with Gravity Forms

Is there any documentation that you are following? https://toolset.com/forums/topic/how-to-upload-multiple-images-with-gravity-forms/

Is there a similar example that we can see?

What is the link to your site?

What I found - but this is based on ACF Gallery:

add_action( 'gform_after_create_post_1', 'lc_gp_media_connect_to_acf_field', 10, 3 );
/**
 * Attach the uploaded images to the created post.
 *
 * @param int   $post_id    The Post ID for the post created with the form.
 * @param array $lead       The Lead Object.
 * @param array $form       The Form Object for the form used to create the post.
 */
function lc_gp_media_connect_to_acf_field( $post_id, $lead, $form ) {

	// Is the gp_media_library perk activated?
	if ( ! function_exists( 'gp_media_library' ) )
		return;

	$file_ids = gp_media_library()->get_file_ids( rgar( $lead, 'id' ), 2 );

	update_post_meta( $post_id, 'gallery', $file_ids );

}

And based on the reply from Your supporter:

In Toolset side, the custom multiple instance fields store same meta_key value but different meta_value value, for example:
meta_key: wpcf-my-field, meta_value: hidden link
meta_key: wpcf-my-field, meta_value: hidden link

One thing need to pay attention to:
If the custom field is created with Toolset Types plugin, you need to prepend "wpcf-" before field slug in your custom PHP codes, for example custom field "my-field", in WP database table "wp_postmeta", column "meta_key" value is "wpcf-my-field"

If You could help me to change the above function, that I will get my files in my Image type field.

What woud be the meta_value? Is this the link from the image?

Regards,

Simon

#2010235

Hello,

I assume we are talking about a custom image field "gallery" created with Toolset Types plugin.

If it is, you will need to use "wpcf-gallery" as field slug, you can try to modify your PHP codes, like these:

add_post_meta($post_id, 'wpcf-gallery', '<em><u>hidden link</u></em>');
add_post_meta($post_id, 'wpcf-gallery', '<em><u>hidden link</u></em>');

More help:
https://developer.wordpress.org/reference/functions/add_post_meta/
Adds a meta field to the given post.

#2010237

Dear Luo

Right - correct.

So I should change the code above, that it is updating according to how many images I will have... and find the url from the image first?

Are You able to help? Or is this out of the support scope?

Regards,

Simon

#2010239

The codes you mentioned above is using Gravity Forms plugin action hooks and functions, they are out the rang of Toolset support range.

Here is my suggestion:
1) Use Gravity Forms plugin action hooks and functions, get the uploaded image file URLs as PHP array, you can check Gravity Forms support for it
hidden link
2) make a loop:
hidden link
3) Then add each image file URL into your database with WP function:
add_post_meta()