9. Submission Hooks | Form Forge - Build Forms with AI in Seconds
Download Log in

9. Submission Hooks

Developer Guide

Actions that fire during and after the form submission lifecycle. All hooks use the formforge_ prefix.

formforge_before_submit

Fires before a form submission is saved to the database. Receives the form ID, the decoded submission data array, and the full form object.

Block submissions from a specific IP address:
php
add_action( 'formforge_before_submit', function( $form_id, $data, $form ) {
    $ip = $_SERVER['REMOTE_ADDR'] ?? '';
    if ( $ip === '192.168.1.100' ) {
        wp_send_json_error( [ 'message' => 'Submissions from this IP are blocked.' ] );
    }
}, 10, 3 );
Add UTM tracking data as hidden fields:
php
add_action( 'formforge_before_submit', function( $form_id, &$data, $form ) {
    $data['custom_source'] = [
        'label' => 'Source',
        'value' => sanitize_text_field( $_POST['utm_source'] ?? 'direct' ),
        'type'  => 'hidden',
    ];
    $data['custom_campaign'] = [
        'label' => 'Campaign',
        'value' => sanitize_text_field( $_POST['utm_campaign'] ?? '' ),
        'type'  => 'hidden',
    ];
}, 10, 3 );

formforge_after_submit

Fires after the submission is saved and all built-in notifications have been dispatched. Receives the submission ID, form ID, and the decoded data array.

Log to a custom analytics table:
php
add_action( 'formforge_after_submit', function( $submission_id, $form_id, $data ) {
    global $wpdb;
    $wpdb->insert( $wpdb->prefix . 'my_form_log', [
        'submission_id' => $submission_id,
        'form_id'       => $form_id,
        'logged_at'     => current_time( 'mysql' ),
    ] );
}, 10, 3 );
Push to a custom CRM via HTTP API:
php
add_action( 'formforge_after_submit', function( $submission_id, $form_id, $data ) {
    if ( $form_id !== 3 ) return;

    $email = '';
    $name  = '';
    foreach ( $data as $field ) {
        if ( $field['type'] === 'email' ) $email = $field['value'];
        if ( $field['type'] === 'text' && empty( $name ) ) $name = $field['value'];
    }

    wp_remote_post( 'https://crm.example.com/api/leads', [
        'headers' => [
            'Authorization' => 'Bearer ' . CRM_API_KEY,
            'Content-Type'  => 'application/json',
        ],
        'body' => wp_json_encode( [
            'name'   => $name,
            'email'  => $email,
            'source' => 'form_forge_' . $form_id,
            'ref'    => 'submission_' . $submission_id,
        ] ),
        'timeout' => 15,
    ] );
}, 10, 3 );

formforge_notification_sent

Fires after an email notification is sent. Useful for logging or triggering follow-up actions.

php
add_action( 'formforge_notification_sent', function( $to, $subject, $body, $form_id ) {
    error_log( sprintf(
        'FormForge: Email sent to %s for form #%d | Subject: %s',
        $to, $form_id, $subject
    ) );
}, 10, 4 );

Forge AI Assistant Online

Hi! I'm the Form Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs