Tag: Hooks

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
Form B

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:

  1. 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
  2. Go to the Actions & Notifications section of the Settings tab
  3. Click the icon to add a 'Send API Data' action
  4. 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 )
  5. Update the settings to save your API call
  6. 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/

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right