Action uncanny-automator

automator_save_cf7_form

Fires after a Contact Form 7 form is saved, providing access to the form and associated recipes.

add_action( 'automator_save_cf7_form', $callback, 10, 3 );

Description

Fires after a Contact Form 7 submission is processed by Uncanny Automator. Developers can use this hook to further process or log form data, access related recipes, and modify trigger arguments before entry creation. It's crucial for custom integrations that need to interact with CF7 submissions after Uncanny Automator's initial handling.


Usage

add_action( 'automator_save_cf7_form', 'your_function_name', 10, 3 );

Parameters

$form (mixed)
The `$form` parameter contains the submitted Contact Form 7 form data.
$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 saved Contact Form 7 form.

Examples

add_action( 'automator_save_cf7_form', 'my_custom_cf7_form_save_logic', 10, 3 );

/**
 * Custom function to process and save Contact Form 7 submission data when triggered by Uncanny Automator.
 *
 * This function demonstrates how to access and utilize the form submission data,
 * related recipes, and arguments passed by Uncanny Automator.
 *
 * @param mixed $form     The Contact Form 7 form object or data.
 * @param mixed $recipes  An array of Uncanny Automator recipes associated with this trigger.
 * @param mixed $args     An array of arguments passed by Uncanny Automator, potentially including user ID and trigger entry details.
 */
function my_custom_cf7_form_save_logic( $form, $recipes, $args ) {
    // Check if we have valid data to process.
    if ( ! empty( $form ) && ! empty( $args ) ) {

        // Example: Log the form ID and the number of recipes found.
        // In a real-world scenario, you might want to extract specific form fields
        // or check against specific recipes before proceeding.
        error_log( sprintf(
            'Uncanny Automator: Saving CF7 form submission. Form ID: %s, Number of recipes found: %d',
            $form->id(), // Assuming $form has an 'id()' method or property like $form['ID']
            count( $recipes )
        ) );

        // Example: Check if a specific recipe is being processed.
        // Replace 'YOUR_RECIPE_ID_TO_TARGET' with an actual recipe ID.
        $target_recipe_id = 'YOUR_RECIPE_ID_TO_TARGET';
        $recipe_matched = false;

        if ( ! empty( $recipes ) ) {
            foreach ( $recipes as $recipe_data ) {
                if ( isset( $recipe_data['ID'] ) && $recipe_data['ID'] == $target_recipe_id ) {
                    $recipe_matched = true;
                    break;
                }
            }
        }

        // If the target recipe is matched, you can perform specific actions.
        if ( $recipe_matched ) {
            error_log( 'Uncanny Automator: Target recipe matched. Performing custom actions for CF7 submission.' );

            // Example: Extracting submitted form data.
            // The structure of $form will depend on how Uncanny Automator passes it.
            // If it's an array of submitted values, you might access them like:
            // $submitted_data = $form['posted_data']; // This is a hypothetical structure.

            // For this example, let's assume $args contains useful trigger metadata.
            if ( isset( $args[0]['user_id'] ) ) {
                $user_id = $args[0]['user_id'];
                error_log( sprintf( 'Uncanny Automator: User ID associated with this submission: %d', $user_id ) );

                // Here you could integrate with another service, update user meta,
                // send a custom notification, etc., based on the form data and user.
                // For instance, if the form had an email field:
                // if ( isset( $submitted_data['email_field_name'] ) ) {
                //     $user_email = sanitize_email( $submitted_data['email_field_name'] );
                //     error_log( 'User submitted email: ' . $user_email );
                // }
            }
        }

        // Important: This hook is an action, so no return value is expected.
        // The logic within this function should perform its intended side effects.
    }
}

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/cf7-subform.php:101
uncanny-automator-pro/src/integrations/contact-form7/triggers/cf7-subfield.php:121

public function wpcf7_submit( $form, $result ) {

		if ( 'validation_failed' !== $result['status'] ) {

			$user_id = wp_get_current_user()->ID;

			$args = array(
				'code'    => $this->trigger_code,
				'meta'    => $this->trigger_meta,
				'post_id' => $form->id(),
				'user_id' => $user_id,
			);

			$args = Automator()->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_cf7_form', $form, $recipes, $args );

			if ( $args ) {
				foreach ( $args as $result ) {
					if ( true === $result['result'] ) {
						Automator()->maybe_trigger_complete( $result['args'] );
					}
				}
			}
		}

	}

Internal Usage

Found in src/integrations/contact-form7/tokens/cf7-tokens.php:24:

add_action( 'automator_save_cf7_form', array( $this, 'automator_save_cf7_form_func' ), 20, 3 );
Scroll to Top