Tell us what you are trying to do?
I have created a set of fields for Woocommerce products including some repeatable fields.
I now need to create a front end form that allows users to add the details into a form - including the repeatable fields.
Can't see how to do it in one form and that also allows users to edit.
In Toolset, repeatable field groups are not managed in the same Form as the post that contains those repeatable field groups. A separate Form is required. Please refer to the documentation here: https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/front-end-forms-for-repeatable-field-groups/
Hi, thanks for that. Can I have multiple forms on a page and one submit button instead of a chained set of forms?
This would give a much better user experience.
No I'm afraid that wouldn't work consistently. Form validation, AJAX, and other API events rely on single Form submission. Plus there's no JavaScript API for Forms, so that type of customization isn't something we could offer here in the forums.
I have used toolset for two years and the amount of coding that is needed goes against how it is advertised. I do like the many features, but ACF and so many page builders are making it easier and simpler to get the results that you actually advertise.
The main frustration as well is that you don't consolidate the knowledge and code snippets across this forum into a useful library of code snippets and tutorials - this adds time and complexity to finding what is often common and repetitive needs.
I will rebuild the site using ACF now - disappointing.
I understand your disappointment
I have created the result with ACF on another site - 1 form 1 submit to create a post.
Before I rebuild the site is there any way that forms can be strung together?
What I want is form 1 creates a pending review/draft of post X1
Form 2 then adds the repeater fields (set 1) to the post information to post X1.
Form 3 then adds the repeater fields (set 2) to the post information to the post X1.
A reviewer can then publish the post.
It depends on what you mean by strung together. You can use custom redirects to accomplish something like this by redirecting the User to a specific URL after submitting a Form. Place Form 1 on Page 1, then place Form 2 on Page 2. Use a custom redirect to automatically send the User to the second page after submitting the first Form. You can add the draft post's ID in the URL as a parent post ID, so the RFG is automatically linked to the parent post. Then you can use another custom redirect for Form 2 to go back to the draft post, or to go to a different page with another Form, or to reload the same page so the User can add another RFG to the draft post right away.
Here is an example of a custom redirect from Form 1 to Page 2, with the newly created post's ID in a URL parameter:
add_filter('cred_success_redirect', 'custom_redirect_form_12345',10,3);
function custom_redirect_form_12345($url, $post_id, $form_data)
{
if ($form_data['id']==12345)
return '<em><u>hidden link</u></em>' . $post_id;
return $url;
}
In this snippet you would replace 12345 with the numeric ID of Form 1. Then you would replace the URL with the appropriate page URL, and replace "slug" with the slug of the parent post type.
Hi Christian, this might be a lifesaver of a solution and thank you for that. I'll test this out and let you know - if it works then it solves the problem.
add_filter('cred_success_redirect', 'custom_redirect_form_761',10,3);
function custom_redirect_form_12345($url, $post_id, $form_data)
{
if ($form_data['id']==761)
return 'hidden link' . $post_id;
return $url;
}
does that look right - I wasn't sure about the url output
what do I put in the field form under 'Set default value from url parameter' see image?
does that look right - I wasn't sure about the url output
function custom_redirect_form_12345($url, $post_id, $form_data)
You should change 12345 to be 761 (matching the function name in the first line).
return '<em><u>hidden link</u></em>' . $post_id;
The default URL parameter will be parent_product_id because the parent post type is WooCommerce Products. The slug of Products is "product". So unless you change the default URL parameter in the Form inputs, you should update the URL parameter to be parent_product_id.
what do I put in the field form under 'Set default value from url parameter' see image?
The default URL parameter will be "parent_product_id". If you want to modify that, you can change it to some other arbitrary name. Then you would update the URL to match that new URL parameter.