Download Log in

21. Custom Notification Channels

Developer Guide

Extend Form Forge to send notifications via channels beyond the built-in email, Slack, Discord, and Telegram.

Building a Custom SMS Notification

php
add_action( 'formforge_after_submit', function( $submission_id, $form_id, $data ) {
    $form = FORMFORGE_Form_Builder::instance()->get( $form_id );
    $settings = $form->settings;

    // Check for a custom SMS setting
    $sms_number = $settings['custom_sms_number'] ?? '';
    if ( empty( $sms_number ) ) return;

    $message = "New submission #{$submission_id} on form: {$form->title}";
    foreach ( $data as $field ) {
        $message .= "n{$field['label']}: {$field['value']}";
    }

    wp_remote_post( 'https://api.twilio.com/2010-04-01/Accounts/ACXXX/Messages.json', [
        'headers' => [
            'Authorization' => 'Basic ' . base64_encode( 'ACXXX:AUTH_TOKEN' ),
        ],
        'body' => [
            'To'   => $sms_number,
            'From' => '+15551234567',
            'Body' => substr( $message, 0, 1600 ),
        ],
        'timeout'  => 10,
        'blocking' => false,
    ] );
}, 10, 3 );

Building a Microsoft Teams Notification

php
add_action( 'formforge_after_submit', function( $submission_id, $form_id, $data ) {
    $teams_webhook = get_option( 'formforge_teams_webhook', '' );
    if ( empty( $teams_webhook ) ) return;

    $form = FORMFORGE_Form_Builder::instance()->get( $form_id );
    $facts = [];
    foreach ( $data as $field ) {
        $facts[] = [ 'name' => $field['label'], 'value' => $field['value'] ];
    }

    $payload = [
        '@type'    => 'MessageCard',
        'summary'  => "New submission: {$form->title}",
        'sections' => [ [
            'activityTitle' => "Form Forge: {$form->title}",
            'facts'         => $facts,
        ] ],
    ];

    wp_remote_post( $teams_webhook, [
        'headers'  => [ 'Content-Type' => 'application/json' ],
        'body'     => wp_json_encode( $payload ),
        'blocking' => false,
    ] );
}, 10, 3 );

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