Send Gravity Forms Entries to a Webhook
Posts every new Gravity Forms entry as JSON, with field labels as keys, to a webhook URL such as Zapier, Make, n8n or your CRM, without the paid webhooks add-on.
Opens WPIDE on
Code
$wpide_gf_webhook_forms = array(); // Form IDs to send; empty = all forms.
add_action( 'gform_after_submission', function ( $entry, $form ) use ( $wpide_gf_webhook_forms ) {
$url = defined( 'WPIDE_GF_WEBHOOK_URL' ) ? (string) WPIDE_GF_WEBHOOK_URL : '';
if ( ! in_array( wp_parse_url( $url, PHP_URL_SCHEME ), array( 'https', 'http' ), true ) || 'spam' === rgar( $entry, 'status' ) ) {
return;
}
if ( $wpide_gf_webhook_forms && ! in_array( (int) $form['id'], array_map( 'intval', $wpide_gf_webhook_forms ), true ) ) {
return;
}
$fields = array();
foreach ( $form['fields'] as $field ) {
if ( in_array( $field->type, array( 'html', 'section', 'page', 'captcha' ), true ) ) {
continue;
}
$label = $field->adminLabel ? $field->adminLabel : $field->label;
$fields[ $label ] = $field->get_value_export( $entry );
}
$body = wp_json_encode( array(
'form_id' => (int) $form['id'],
'form_title' => $form['title'],
'entry_id' => (int) rgar( $entry, 'id' ),
'fields' => $fields,
'source_url' => rgar( $entry, 'source_url' ),
'created' => rgar( $entry, 'date_created' ),
'site' => home_url(),
) );
$headers = array( 'Content-Type' => 'application/json' );
if ( defined( 'WPIDE_GF_WEBHOOK_SECRET' ) && WPIDE_GF_WEBHOOK_SECRET ) {
$headers['X-Signature'] = hash_hmac( 'sha256', $body, WPIDE_GF_WEBHOOK_SECRET );
}
wp_remote_post( $url, array( 'body' => $body, 'headers' => $headers, 'timeout' => 5, 'blocking' => false ) );
}, 10, 2 );
Notes
Define WPIDE_GF_WEBHOOK_URL (and optionally WPIDE_GF_WEBHOOK_SECRET for an X-Signature HMAC header) in wp-config.php; spam entries are never sent.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.