The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Embedding for Minimize & Control
I'm back with some latest discoveries regarding embedded forms. I chose this approach as a recent project I'm working on has 400+ fields, many are dynamic and standard dropdowns with much conditional logic applied. This makes working with a single form almost unbearable. So I chose to take advantage of the new Form Embed function to create multiple easily manageable micro-forms and compile them into one large form.
In this episode we'll be working with csv outputs and gathering form data. I like to have each field shot out to a csv upon creation as it allows me to easily manipulate this extreme amount of data on a line by line basis.
So with that said, only a few changes need to be made to allow for the new embedded data to be sent as one file without the need for a different csv for each micro-form submitted through the main form.
(the embed saves all entries within the compiled form with a new parent_id for each embedded form while also saving the entries into each micro form)
When you embed the form, the field id for the embed becomes the parent_id for the form as well as the corresponding data. So for instance, form A, form B, and form C each have an embed field id of 518, 519, and 520.
Previously I could take form A, get all of the field id's and arrange them as so to get a csv to spit out
//Submit to CSV
add_action('frm_after_create_entry', 'copy_to_csv', 20, 2);
function copy_to_csv($entry_id, $form_id){
if($form_id == 140){ //change to the form id of the form to copy
global $current_user;
$data .= $_POST['item_meta'][6849] . "n" . $_POST['item_meta'][7039] . "n" . $_POST['item_meta'][7038];
$values = file_put_contents('/home/username/public_html/path/csv/MyForm_' . $current_user->user_login . '.csv', $data, FILE_APPEND | LOCK_EX);
}
}
The only change required in this new process if we assume field [6849] is in form A, field [7039] is in form B, and [7298] is in form C is to apply the correct parent_id before the field......
//Submit to CSV
add_action('frm_after_create_entry', 'copy_to_csv', 20, 2);
function copy_to_csv($entry_id, $form_id){
if($form_id == 140){ //change to the form id of the form to copy
global $current_user;
$data .= $_POST['item_meta'][518][0][6849] . "n" . $_POST['item_meta'][519][0][7039] . "n" . ['item_meta'][520][0][7298];
$values = file_put_contents('/home/username/public_html/path/csv/MyForm_' . $current_user->user_login . '.csv', $data, FILE_APPEND | LOCK_EX);
}
}
Now we have a single file with our multiform entries 🙂
This can also be applied for external submissions and anything else you might use a custom after_submit function for if you'd like to keep everything tidy by your compiled form.
Until next time........Cheers
Discussion closed.