automator_save_forminator_form_entry
Fires after a Forminator form entry is saved, providing access to form ID, recipes, and arguments.
add_action( 'automator_save_forminator_form_entry', $callback, 10, 3 );
Description
Fires after a Forminator form entry is saved. Developers can use this hook to perform custom actions, modify saved data, or trigger additional processes based on the submitted form and associated recipes. It's called when an entry is successfully processed and stored, providing access to the form ID, relevant recipes, and additional arguments.
Usage
add_action( 'automator_save_forminator_form_entry', 'your_function_name', 10, 3 );
Parameters
-
$form_id(mixed) - This parameter holds the ID of the Forminator form for which an entry was saved.
-
$recipes(mixed) - This parameter holds the unique identifier for the Forminator form that was submitted.
-
$args(mixed) - This parameter contains an array of all the recipes that are being triggered by this specific Forminator form submission.
Examples
<?php
/**
* Example function to hook into 'automator_save_forminator_form_entry'
* to log Forminator form entry data for Uncanny Automator processing.
*
* @param mixed $form_id The ID of the submitted Forminator form.
* @param mixed $recipes An array of Uncanny Automator recipes associated with this form.
* @param mixed $args An array containing arguments related to the trigger entry processing.
*/
add_action( 'automator_save_forminator_form_entry', function( $form_id, $recipes, $args ) {
// Ensure we have valid data to process.
if ( ! $form_id || ! is_array( $recipes ) || ! is_array( $args ) ) {
return;
}
// Log the form ID and the number of recipes found for debugging or auditing.
error_log( sprintf( 'Automator: Processing Forminator form submission for Form ID: %d with %d recipes.', $form_id, count( $recipes ) ) );
// Further process the $args to extract relevant trigger data if needed.
// For example, you might want to check if the trigger entry was successfully created.
if ( isset( $args[0]['result'] ) && true === $args[0]['result'] ) {
$trigger_id = isset( $args[0]['args']['trigger_id'] ) ? (int) $args[0]['args']['trigger_id'] : 0;
$user_id = isset( $args[0]['args']['user_id'] ) ? (int) $args[0]['args']['user_id'] : 0;
error_log( sprintf( 'Automator: Trigger entry saved successfully. Trigger ID: %d, User ID: %d.', $trigger_id, $user_id ) );
// Here you could perform additional actions, like saving specific form field data
// to the trigger meta or initiating further automator processes based on the form submission.
// For instance, if $args contained detailed form field data:
// if ( ! empty( $args[0]['args']['fields'] ) ) {
// foreach ( $args[0]['args']['fields'] as $field_key => $field_value ) {
// // Process or save $field_key and $field_value
// }
// }
} else {
error_log( 'Automator: Failed to save trigger entry for Forminator form submission.' );
}
}, 10, 3 );
?>
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/forminator/triggers/anon-fr-submitform.php:96
src/integrations/forminator/triggers/fr-submitform.php:93
uncanny-automator-pro/src/integrations/forminator/triggers/fr-submitfield.php:130
public function fr_submit_form( $entry, $form_id, $field_data_array ) {
$user_id = get_current_user_id();
$args = array(
'code' => $this->trigger_code,
'meta' => $this->trigger_meta,
'post_id' => intval( $form_id ),
'user_id' => intval( $user_id ),
);
$args = Automator()->process->user->maybe_add_trigger_entry( $args, false );
//Adding an action to save contact form submission in trigger meta
$recipes = Automator()->get->recipes_from_trigger_code( $this->trigger_code );
do_action( 'automator_save_forminator_form_entry', $form_id, $recipes, $args );
if ( $args ) {
foreach ( $args as $result ) {
if ( true === $result['result'] ) {
if ( ! empty( $field_data_array ) ) {
$trigger_id = (int) $result['args']['trigger_id'];
$user_id = (int) $user_id;
$trigger_log_id = (int) $result['args']['get_trigger_id'];
$run_number = (int) $result['args']['run_number'];
$meta_key = (string) $this->trigger_meta;
foreach ( $field_data_array as $entry_field ) {
$field_meta = "{$trigger_id}:{$meta_key}:{$form_id}|" . $entry_field['name'];
$insert = array(
'user_id' => $user_id,
'trigger_id' => $trigger_id,
'trigger_log_id' => $trigger_log_id,
'meta_key' => $field_meta,
'meta_value' => maybe_serialize( $entry_field['value'] ),
'run_number' => $run_number,
);
Automator()->process->user->insert_trigger_meta( $insert );
}
}
Automator()->process->user->maybe_trigger_complete( $result['args'] );
}
}
}
}
Internal Usage
Found in src/integrations/forminator/tokens/fr-tokens.php:22:
add_action( 'automator_save_forminator_form_entry', array( $this, 'fr_save_form_entry' ), 10, 3 );