Can a form save multiple entries per submit?

By: Phil Cox | Asked: 03/24/2025
ForumsCategory: General questionsCan a form save multiple entries per submit?
Phil Cox asked 1 month ago

Hi,

I have a booking form that correctly books multiple events per submission. Until now, it has been fine to select all the required events, then generate an entry that lists them all. The need has changed, however and I now need to refactor the form to save one entry per event.

 The required events are selected as options in a checkbox field.

 Would it be possible to hook the saving mechanism and loop through the selected options, saving an entry for each checked option?

 The entries are saved in a different form (booking_data) using the API, to separate the data from the capture function.

Could the modified save mechanism be extended to the API action, so the multiple entries are saved in the other form?

I tried support but they haven't come across this requirement before. Does that mean I'm over-complicating it?

Thanks,
Phil.

2 Answers
Victor Font Staff answered 1 month ago

Yes to all with custom programming. You would use the frm_after_create_entry hook to loop through the selected options and use Formidable's form creating function.

Phil Cox replied 1 month ago

Thanks Victor,
I'll follow up on frm_after_create_entry and how to loop through selected options.
Please could you clarify what I should research for "Formidable's form creating function"?
Many thanks,
Phil.

Phil Cox replied 1 month ago

Thanks very much. I'll see what I can do.

Victor Font Staff replied 1 month ago

Here's a hint. In the frm_after_creat_entry hook, loop through the $_POST array as the data source. $_POST is a PHP global.

Phil Cox replied 1 month ago

Thanks Victor - I remembered that the API isn't necessary for creating entries in another form on the same site. Simplifies things.

Phil Cox answered 4 weeks ago

For completeness and to help anyone else who followed the thread, here is the code that provided the basis for a solution: 

add_action('frm_after_create_entry', 'create_multiple_entries_after_submission', 30, 2);

function create_multiple_entries_after_submission($entry_id, $form_id){
    if ( $form_id != 72 ) {//Change 72 to the ID of Form A
        return;
    }

    $form2 = '73';//Change 73 to the ID of Form B
	
	//Read Form A "options" field into an array.
	$array = $_POST['item_meta'][1161]; //Change 1161 to the ID of the "Options" field in Form A.
	foreach($array as $value) //loop over values
	{
		//Create entry
		FrmEntry::create(array(
		'form_id' => $form2,
		'frm_user_id' => $user,
		'item_meta' => array(
			// list all fields to be copied to multiple entries
			1162 => $value, //Copies the particular option to the new entry.  Can be used for a title or similar.
			// Change 1162 t othe ID of the field in Form B you want to store the option.
			// N.B. $value MUST be used within the loop or entries are not saved.
			1157 => $_POST['item_meta'][1156],
			// Change 1156 to the ID of the source field in Form A. 
			// Change 1157 to the ID of a field in Form B you want to populate with the value from Form A.
			// Repeat for all other required fields
			),
		));
	}       
}
Victor Font Staff replied 3 weeks ago

Nice job Phil!

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