There are examples on the Formidable site for sending data from repeaters in one form to repeaters in another, but nothing that matched this scenario so I hope this tutorial is of use. It can be adapted for a situation where from A has any number of repeaters as long as Form B has none.
You will need the API add on and an active licence for this to work.
Example scenario:
On submission of Form A a new entry is created in Form B for every row in the relevant Form A repeater(s):
Form A
- Field A1 : Text
- Field A2 : Radio (Option 1 / Option 2)
- Field A3 : Repeater Section (shows if Field A2 val is option 1)
- Field A3a : Text
- Field A3b : Text
- Field A3c : Text
- Field A4 : Text
- Field A5 : Text
- Field A6 : Repeater Section (shows if Field A2 val is option 2)
- Field A6a : Text
- Field A6b : Text
- Field A6c : Text
- Field A6d : Text
- Field A6e : Text
- Field A7 : Text
Form B
- Field B1: Text (populated by either Field A3a or Field A6a)
- Field B2: Text (populated by either Field A3b or Field A6b)
- Field B3: Text (populated by either Field A3c or Field A6c)
- Field B4: Text (populated by Field A6d – can be blank)
- Field B5: Text (populated by Field A6e – can be blank)
Solving the problem using the API add on
The first thing to note is that you can only include fields inside the repeater using this approach so if you need data from elsewhere in the form you will either need to use javascript to copy it into hidden fields in the repeater on the fly or use the frm_validate_field_entry hook to copy on submission - I did the latter.
Unfortunately, you cannot set up a ‘foreach’ argument in the ‘out of the box’ API json builder to handle the repeaters.
What you can do is create an action using the API add on in the settings of each of the child forms that were generated when you created your repeaters and then add a code snippet to trigger them.
To do this follow the steps below:
- Go to the settings page of Form A and in the URL bar of your web browser replace the form ID with that of the first repeater (you can find this by going to the Formidable Import/Export screen and searching for the relevant child form – the form ID will be alongside it) and hit enter - you are now in the child form settings
- Go to the Actions & Notifications section of the Settings tab
- Click the icon to add a 'Send API Data' action
- Follow the instructions on the Formidable site to create an entry in another form (https://formidableforms.com/knowledgebase/formidable-api/#kb-create-an-entry-in-another-form )
- Update the settings to save your API call
- Repeat steps 1-5 for your second repeater (if you have one)
If you tested at this point your API actions would not run because form actions are not triggered by default when either child or embedded forms are submitted. To fix this you need to use a form action hook* to force this to happen. This is the one you need to use: https://formidableforms.com/knowledgebase/frm_use_embedded_form_actions/#kb-examples
I only wanted the triggers to fire on these two child forms so I used the second example, but I changed line 3 from:
if ( $args['form']->id == 123) {
to:
if ( $args['form']->id == 421 || $args['form']->id == 422 ) {
Change 421 to the id of your first child form and 422 to the id of the second child form so that the snippet will run if the form has either of those ids.
If you have found a better approach please do share 😊
*you can find more information on using Formidable Hooks here: https://formidableforms.com/knowledgebase/formidable-hooks/