automator_save_anon_cf7_form
Fires when an anonymous Contact Form 7 form is saved, providing form data and associated recipes for further processing.
add_action( 'automator_save_anon_cf7_form', $callback, 10, 3 );
Description
Fires after an anonymous Contact Form 7 submission is processed but before it's saved to trigger entries. Developers can use this hook to further process or modify the form data, recipes, and arguments before the automation trigger is finalized. This is useful for custom data handling or conditional logic specific to anonymous form submissions.
Usage
add_action( 'automator_save_anon_cf7_form', 'your_function_name', 10, 3 );
Parameters
-
$form(mixed) - This parameter represents the Contact Form 7 form object being submitted.
-
$recipes(mixed) - This parameter represents the Contact Form 7 form object that was submitted.
-
$args(mixed) - This parameter contains an array of recipes that are associated with the current anonymous Contact Form 7 submission.
Examples
<?php
/**
* Example function to process and save Contact Form 7 submissions for anonymous users.
* This function is hooked into the 'automator_save_anon_cf7_form' action.
*
* @param mixed $form The Contact Form 7 form object or data.
* @param array $recipes An array of Uncanny Automator recipes associated with this trigger.
* @param array $args An array of arguments, typically containing trigger entry data.
*/
function my_automator_handle_anonymous_cf7_submission( $form, $recipes, $args ) {
// Ensure we have data to work with.
if ( empty( $form ) || empty( $recipes ) || empty( $args ) ) {
return;
}
// In a real scenario, you'd likely want to log this or perform specific actions.
// For demonstration, we'll log the form ID and the number of recipes found.
// You might access form data like this (assuming $form is an array or object with a 'ID' or 'id' property):
$form_id = isset( $form['ID'] ) ? $form['ID'] : ( isset( $form->id ) ? $form->id : 'N/A' );
error_log( sprintf(
'Automator: Saving anonymous CF7 form submission. Form ID: %s, Recipes found: %d',
$form_id,
count( $recipes )
) );
// Further processing might involve extracting specific field values from $form
// and matching them against recipe requirements, or updating custom meta data.
// For instance, if $form contains submitted values:
if ( is_array( $form['posted_data'] ) ) {
foreach ( $form['posted_data'] as $field_name => $field_value ) {
// Example: If a form field is 'email', you might want to store it.
if ( 'your_cf7_email_field_name' === $field_name ) {
// Here you would typically use Uncanny Automator's functions
// to save this data as part of the trigger entry or for token usage.
// This is a simplified example. The actual saving logic is handled by
// Uncanny Automator's core functions.
error_log( sprintf(
'Automator: Captured field "%s" with value "%s"',
$field_name,
sanitize_text_field( $field_value )
) );
}
}
}
// The original code already handles calling maybe_trigger_complete within the loop.
// This function's purpose is more about pre-processing or logging before that happens.
}
// Hook the custom function to the 'automator_save_anon_cf7_form' action.
// We use a priority of 20 and accept 3 arguments as indicated by the source context.
add_action( 'automator_save_anon_cf7_form', 'my_automator_handle_anonymous_cf7_submission', 20, 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/contact-form7/triggers/anon-cf7-subform.php:98
uncanny-automator-pro/src/integrations/contact-form7/triggers/anon-cf7-subfield.php:113
public function wpcf7_submit( $form, $result ) {
if ( 'validation_failed' === (string) $result['status'] ) {
return;
}
$args = array(
'code' => $this->trigger_code,
'meta' => $this->trigger_meta,
'post_id' => $form->id(),
'user_id' => 0,
);
$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_anon_cf7_form', $form, $recipes, $args );
if ( $args ) {
foreach ( $args as $result ) {
if ( true === $result['result'] ) {
Automator()->process->user->maybe_trigger_complete( $result['args'] );
}
}
}
}
Internal Usage
Found in src/integrations/contact-form7/tokens/cf7-tokens.php:25:
add_action( 'automator_save_anon_cf7_form', array( $this, 'automator_save_cf7_form_func' ), 20, 3 );
Found in uncanny-automator-pro/src/integrations/contact-form7/tokens/cf7-anon-tokens.php:24:
add_action( 'automator_save_anon_cf7_form', array( $this, 'automator_save_anon_cf7_form_func' ), 20, 3 );