Bricks Builder Forms Integration

Bricks is a premium WordPress theme that lets you visually build performant WordPress sites and uses what are called elements. Elements are very similar to blocks. The Bricks’ “Form” element allows the building and placement of forms on any page built with Bricks. The form element lets you build custom forms, the data in these forms can be added to contacts in Groundhogg. 

Requirements: Groundhogg, Advance Features ExtensionBricks Builder

  1. Create a Page, Edit with Bricks, Add a form
  2. In our example we are going to get the Email ID, (Example: d2525e)
    *An email address is required to create a Contact in Groundhogg
  3. Expand Fields, click the Email field, at the bottom you will find the ID

  4. Copy the ID, we'll be using it in the code snippet
  5. Expand Actions, click the field to select "custom"

  6. Publish your form
Copy this bit of code below and place it in your theme's functions.php file or in a Code Snippet plugin
/* Bricks Builder Form Integration with Groundhogg */
function bricks_connect_to_groundhogg( $form ) {

	$fields  = $form->get_fields();
	$form_id = $fields['formId'];

	/*
	 * Map of bricks fields Ids to corresponding contact field
	 *
	 * For example
	 *
	 * [
	 *   'form-field-ID' => 'email'
	 * ]
	 */
	$field_map = [
		'form-field-0c690e' => 'email'
	];

	$contact = \Groundhogg\generate_contact_with_map( $fields, $field_map );

	if ( ! \Groundhogg\is_a_contact( $contact ) ){
		$form->set_result([
			'action' => 'groundhogg',
			'type'    => 'error', // or 'error' or 'info'
			'message' => esc_html__('Unable to create contact', 'bricks'),
		]);
	}
}
add_action( 'bricks/form/custom_action', 'bricks_connect_to_groundhogg', 10, 1 );
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us