# Post Gravity Forms Entries to Slack

> Sends a short summary of each new Gravity Forms entry to a Slack channel with a link to the entry, so your team can respond to leads quickly.

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

## Code

```php
add_action( 'gform_after_submission', function ( $entry, $form ) {
    $url = defined( 'WPIDE_SLACK_WEBHOOK_URL' ) ? (string) WPIDE_SLACK_WEBHOOK_URL : '';

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

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

    $lines = array( sprintf( '*New entry in "%s"*', $escape( $form['title'] ) ) );
    foreach ( $form['fields'] as $field ) {
        $value = trim( wp_strip_all_tags( (string) $field->get_value_export( $entry ) ) );
        if ( '' !== $value && count( $lines ) < 6 ) {
            $lines[] = sprintf( '*%s:* %s', $escape( $field->label ), $escape( wp_html_excerpt( $value, 300, '…' ) ) );
        }
    }
    $lines[] = '<' . admin_url( 'admin.php?page=gf_entries&view=entry&id=' . (int) $form['id'] . '&lid=' . (int) rgar( $entry, 'id' ) ) . '|Open the entry>';

    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, 2 );
```

## Notes

Create a Slack incoming webhook and define WPIDE_SLACK_WEBHOOK_URL in wp-config.php; only the first five filled fields are included.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Post Gravity Forms Entries 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/
