groundhogg/form/submission_handler/after

This Groundhogg hook executes after the submission handler successfully handles the submission request.

do_action( 'groundhogg/form/submission_handler/after', $submission, $contact, $this );

To use this hook, you are essentially hooking into an action that occurs after a form submission in the Groundhogg plugin for WordPress. Here's how you can use this hook with an example:

Understanding the Hook:
  • Action Hook: 'groundhogg/form/submission_handler/after'
  • Parameters:
    • $submission : This is the submission object from the form, containing all the data submitted.
    • $contact : This is the contact object associated with the form submission.
    • $this : This refers to the instance of the class or context where the form handler is called.
Example Use Case: Let's say you want to perform some custom logging or additional processing after a form is submitted:
// Add your custom action to the hook
add_action( 'groundhogg/form/submission_handler/after', 'custom_after_submission_action', 10, 3 );

function custom_after_submission_action( $submission, $contact, $form_handler ) {
    // Log the submission data
    error_log( "Form Submission: " . print_r( $submission, true ) );
    
    // Example: Send an email notification
    $email = $contact->email;
    
    // Assuming you have a function to send emails
    send_custom_email( $email, "Form Submission Received", "Thanks for submitting the form!" );
    
    // Or maybe update some custom fields in the contact
    $contact->update_meta( 'last_submitted_form', $submission->form_id );
}
Explanation:
  • Hook Registration: add_action( 'groundhogg/form/submission_handler/after', 'custom_after_submission_action', 10, 3 ); registers your function custom_after_submission_action to run after the form submission handler. The 10 is the priority, and 3 indicates that the function accepts three arguments, aligning with $submission, $contact, and $form_handler.
  • Function Implementation: In custom_after_submission_action, you can perform actions like logging, sending notifications, updating contact data, etc., using the data provided by the $submission and $contact objects.
Additional Considerations:
  • Ensure that any functions like send_custom_email or methods like update_meta are defined elsewhere in your plugin or theme if they are not part of Groundhogg's API.
  • Always check for the existence of properties or methods before using them to avoid errors, especially if you're not certain about the structure of the $submission or $contact objects.

This approach allows you to extend the functionality of Groundhogg's form submission process without modifying its core code, which is beneficial for plugin updates and maintenance.

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