\Groundhogg\Submission

📅 Published on

📝 Last updated

Documentation

»

Classes

»

\Groundhogg\Submission

extends Base_Object_With_Meta

Represents a single form submission record. Every time a Groundhogg form is submitted, a Submission object is created and stored. It holds the form answers, the associated contact, and the step (form) that was submitted.

Methods

MethodReturnsDescription
get_form_id()intReturns the ID of the form (step) that was submitted.
get_step_id()intReturns the step ID (same as get_form_id()).
get_contact_id()intReturns the ID of the contact who submitted the form.
get_contact()ContactReturns the Contact object.
get_date_created()stringReturns the submission date as a MySQL datetime string.
get_answers( $include_hidden = false )arrayReturns an associative array of field name → value pairs. Pass true to include hidden fields.
add_posted_data( $array )boolAdds raw posted field data to the submission record.
get_as_array()arrayReturns a serialisable representation of the submission.

Usage

Here’s a pseudo code example for a hypothetical form submission data export integration.

<?php

add_action( 'groundhogg/form/v2/submit', 'my_plugin_forward_submission', 10, 3 );

/**
 * Forward form answers to an external service when a specific form is submitted.
 *
 * @param \Groundhogg\Submission $submission
 * @param \Groundhogg\Form_v2    $form
 * @param \Groundhogg\Contact    $contact
 *
 * @return void
 */
function my_plugin_forward_submission( $submission, $form, $contact ) {

    if ( $submission->get_form_id() !== MY_PLUGIN_TARGET_FORM_ID ) {
        return;
    }

    $answers = $submission->get_answers();

    wp_remote_post( MY_PLUGIN_WEBHOOK_URL, [
        'body' => array_merge( $answers, [
            'contact_email' => $contact->get_email(),
            'submitted_at'  => $submission->get_date_created(),
        ] ),
    ] );
}

Was this helpful?

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