Skip Navigation

[Resolved] Repeatable fields in CRED form don't generate multiple file links.

This support ticket is created 3 years, 3 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by Christian Cox 3 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#2132167

I have a form which accepts multiple file links.
hidden link

Yet it only generates a single link in the content output.
hidden link

And it appears to concatenate the URLs into a single link, which of course produces a 404 error.
hidden link

#2132919
Screen Shot 2021-08-03 at 4.56.41 PM.png

Yet it only generates a single link in the content output.
Hello, can you describe how you are including this custom field in your template or post contents?
- Typically the best option for displaying a field that allows multiple values is the Repeating Field block (screenshot attached here).
- If you are using a different block in the Block Editor, please explain which block, and if possible provide some screenshots so I can see the block configurations.
- If you are using a shortcode or a series of shortcodes, please copy + paste those here for me to review, and tell me where you have placed these shortcodes.
- If you are using custom PHP, please copy + paste that code here fo me to review.

#2133105

Thanks for the feedback.
I'm using Beaver Builder with Beaver Themer.

Themer has the ability to insert ToolSet Custom fields into a page from their Text Editor module.
hidden link

As you can see from this screenshot I have enabled the field as "repeatable".
hidden link

#2134037

Okay I see, unfortunately we don't really have any control over how Beaver Themer/Beaver Builder renders Toolset fields. The code that determines how the fields are rendered is managed in their plugins, and Toolset does not really influence how their software implements data from Types fields. I suggest reaching out to their support team to let them know this feature is not working as expected with repeating file fields, so they can correct the behavior in their software.

Until they can address the problem, have you tried using a Types field shortcode instead? You can try inserting this shortcode in the Text Editor instead of using the Beaver Themer feature to insert a field:

[types field="article-pdf" separator=" "][/types]

That should output the repeated file links, each one separated by a space.

#2135219

"Until they can address the problem, have you tried using a Types field shortcode instead?"

Is there a way to wrap these raw links individually in other HTML e.g., using them as the href attributes of one or more anchor tags?

#2135239

Is there a way to wrap these raw links individually in other HTML e.g., using them as the href attributes of one or more anchor tags?
If you mean you want to customize the HTML that wraps each link, yes, there are different approaches that allow for different types of customization. You can use the wpv-for-each shortcode to apply a custom HTML markup template to all instances of the field in a loop. Customizing the template to be unique for each instance is not really intuitive in this approach.
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-for-each
Notice the field slugs and the use of the wpcf- prefix in the following example:

[wpv-for-each field="wpcf-article-pdf"]
<a href="[types field='article-pdf' output='raw'][/types]">Download [types field='article-pdf' output='raw'][/types]</a>
[/wpv-for-each]

The wpcf- prefix is required in the wpv-for-each field attribute, but should not be used in the loop template. Notice that the template is not really easily adjustable for individual instances, beyond the field value itself.

Another option is you can use the Types field shortcode and access individual instances directly by instance index number. This gives you more flexibility in terms of customizing the template for each instance, but isn't integrated with any kind of looping mechanism.
https://toolset.com/documentation/customizing-sites-using-php/functions/#file (click the orange +More link)
Example:

<a href="[types field='article-pdf' index='0' output='raw'][/types]">Download the first file</a> |
<a href="[types field='article-pdf' index='1' output='raw'][/types]">Download the second file</a> | 
<a href="[types field='article-pdf' index='2' output='raw'][/types]">Download the third file</a>

Since there is no looping structure to repeat a template, you might end up with extra links or too few links depending on the number of field instances.

For the most flexibility, create a custom shortcode using PHP and build your links by looping over the values from get_post_meta, something like:

$html = '';
$files = get_post_meta( 12345, 'wpcf-article-pdf', false);
$index = 1;
foreach($files as $file) {
  $html .= '<a href="' . $file . '">Download file #' . $index . '</a>';
  $index++;
}
return $html;

https://codex.wordpress.org/Shortcode_API