# Post WPForms Submissions to Slack

> Sends a summary of each WPForms submission to a Slack channel through an incoming webhook, so the team sees new enquiries straight away.

- Type: PHP
- Runs: Run everywhere
- Category: [Forms](https://wpide.com/library/category/forms/)
- Tags: wpforms, slack, notifications
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/wpforms-slack-notification/

## Code

```php
add_action( 'wpforms_process_complete', function ( $fields, $entry, $form_data ) {
    $url = defined( 'WPIDE_SLACK_WEBHOOK_URL' ) ? (string) WPIDE_SLACK_WEBHOOK_URL : '';

    if ( 0 !== strpos( $url, 'https://hooks.slack.com/' ) ) {
        return;
    }

    $escape = function ( $text ) {
        return str_replace( array( '&', '<', '>' ), array( '&amp;', '&lt;', '&gt;' ), (string) $text );
    };

    $title = isset( $form_data['settings']['form_title'] ) ? $form_data['settings']['form_title'] : 'WPForms';
    $lines = array( sprintf( '*New submission: %s*', $escape( $title ) ) );

    foreach ( (array) $fields as $field ) {
        $value = isset( $field['value'] ) ? trim( wp_strip_all_tags( (string) $field['value'] ) ) : '';
        if ( '' !== $value && count( $lines ) < 7 ) {
            $lines[] = sprintf( '*%s:* %s', $escape( $field['name'] ), $escape( wp_html_excerpt( $value, 300, '…' ) ) );
        }
    }

    wp_safe_remote_post( $url, array(
        'body'     => wp_json_encode( array( 'text' => implode( "\n", $lines ) ) ),
        'headers'  => array( 'Content-Type' => 'application/json' ),
        'timeout'  => 5,
        'blocking' => false,
    ) );
}, 10, 3 );
```

## Notes

Define WPIDE_SLACK_WEBHOOK_URL in wp-config.php; only the first six filled fields are included.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Post WPForms Submissions to Slack" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
