Skip Navigation

[Resolved] Need to get Repeating Image Field URLs in CRED Form for PHP…

This thread is resolved. Here is a description of the problem and solution.

Problem:
The customer asked how to get the image URLs from a repeating image field when the Toolset Form is submitted.

Solution:
Suggested to use the "cred_save_data" hook with a code example.

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

https://toolset.com/documentation/customizing-sites-using-php/functions/#image

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.

Our next available supporter will start replying to tickets in about 0.93 hours from now. Thank you for your understanding.

This topic contains 2 replies, has 2 voices.

Last updated by shawnW-3 1 month, 3 weeks ago.

Assigned support staff: Waqar.

Author
Posts
#2386765

Tell us what you are trying to do?
The long story is I need to convert images to base64 to add them as attachments to a CRM via API...

BUT my understanding is that in order to encode these images I need to first access the URLs of these images.

So something like $_POST["wpcf-problem-images-contact"] isn't going to get me what I need.

So, like the subject says, I need to access what I suspect is a value inside the field, and being a repeating field complicates that further.

Is there any documentation that you are following?
https://toolset.com/documentation/customizing-sites-using-php/functions/
https://toolset.com/documentation/programmer-reference/cred-api/#cred_form_ajax_upload_validate

Is there a similar example that we can see?
No.

What is the link to your site?
N/A

#2387123

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

To get the image URLs from a repeating image custom field, you can use the 'cred_save_data' hook, with the Types fields API function, for example:


add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
    // if a specific form
    if ($form_data['id']==12345)
    {
        $images = types_render_field( "image-field-slug", array( "item" => $post_id, "output" => "raw", "separator" => "," ) );
    }
}

Note: You'll replace "12345" with the form's ID and the "image-field-slug" with the repeating image field's slug and you'll get the comma-separated list of image URLs in the '$images' variable.

Related documents:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data
https://toolset.com/documentation/customizing-sites-using-php/functions/#image

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#2389181

Sorry for the delayed response. This was EXACTLY what I was needing. Many thanks! My issue is resolved now.