[Documentation](https://groundhogg.io/documentation/) » [Functions](https://groundhogg.io/documentation/#doc-functions)

# after_form_submit_handler

Published Tuesday, December 2, 2025 · Last updated Tuesday, June 9, 2026

The `after_form_submit_handler()` function handles many post-form submission tasks, such as…

- Setting up the tracking cookie
- Resetting the opt-in status if required
- Captures page visit history
- UTM tracking
- Etc…

In order to use it, a contact record must have been previously created so that it can be passed to this function.

## Parameters

| Parameter | Type | Description |
| --- | --- | --- |
| `$contact` | `Contact` | Passed by reference. The contact who submitted the form. |

## Return value

`void` —

## Usage

```

<?php

$contact = new \Groundhogg\Contact( [ 'email' => 'hello@example.com' ] );

\Groundhogg\after_form_submit_handler( $contact );
```

## Example

Here’s a pseudo code example for a hypothetical integration.

```

<?php

add_action( 'my_custom_form_integration', 'my_custom_form_integration_after_form_submit_handler' );

/**
 * Create a contact record and then call `after_form_submit_handler()`.
 *
 * @param array $data
 *
 * @return void
 */
function my_custom_form_integration_after_form_submit_handler( $data ){

	$contact = new \Groundhogg\Contact( [
		'first_name' => sanitize_text_field( $data['first_name'] ),
		'last_name'  => sanitize_text_field( $data['last_name'] ),
		'email'      => sanitize_email( $data['email'] ),
	] );

	if ( ! $contact->exists() ){
		throw new \Exception( 'Could not create contact record.' );
	}

	\Groundhogg\after_form_submit_handler( $contact );
}
```
