after_form_submit_handler

📅 Published on

📝 Last updated

We’re currently revamping our documentation for 4.0.
See old documentation →

Documentation

»

Functions

»

after_form_submit_handler

Related Docs

On this page

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.

<?php

$contact = new \Groundhogg\Contact( [ 'email' => '[email protected]' ] );

\Groundhogg\after_form_submit_handler( $contact );

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 );
}

Was this helpful?

Let us know if this document answered your question. That’s the only way we can improve.