Send WPForms Entries to a Webhook
Posts every WPForms submission as JSON with field labels as keys to a webhook URL, such as Zapier, Make, n8n or a CRM, without a paid add-on.
Opens WPIDE on
Code
$wpide_wpf_webhook_forms = array(); // Form IDs to send; empty = all.
add_action( 'wpforms_process_complete', function ( $fields, $entry, $form_data, $entry_id ) use ( $wpide_wpf_webhook_forms ) {
$url = defined( 'WPIDE_WPFORMS_WEBHOOK_URL' ) ? (string) WPIDE_WPFORMS_WEBHOOK_URL : '';
if ( ! in_array( wp_parse_url( $url, PHP_URL_SCHEME ), array( 'https', 'http' ), true ) ) {
return;
}
if ( $wpide_wpf_webhook_forms && ! in_array( (int) $form_data['id'], array_map( 'intval', $wpide_wpf_webhook_forms ), true ) ) {
return;
}
$data = array();
foreach ( (array) $fields as $field ) {
$label = ! empty( $field['name'] ) ? $field['name'] : 'field_' . $field['id'];
$data[ $label ] = isset( $field['value'] ) ? $field['value'] : '';
}
$body = wp_json_encode( array(
'form_id' => (int) $form_data['id'],
'form_title' => isset( $form_data['settings']['form_title'] ) ? $form_data['settings']['form_title'] : '',
'entry_id' => (int) $entry_id,
'fields' => $data,
'submitted' => gmdate( 'c' ),
'site' => home_url(),
) );
$headers = array( 'Content-Type' => 'application/json' );
if ( defined( 'WPIDE_WPFORMS_WEBHOOK_SECRET' ) && WPIDE_WPFORMS_WEBHOOK_SECRET ) {
$headers['X-Signature'] = hash_hmac( 'sha256', $body, WPIDE_WPFORMS_WEBHOOK_SECRET );
}
wp_remote_post( $url, array( 'body' => $body, 'headers' => $headers, 'timeout' => 5, 'blocking' => false ) );
}, 10, 4 );
Notes
Define WPIDE_WPFORMS_WEBHOOK_URL (and optionally WPIDE_WPFORMS_WEBHOOK_SECRET for an X-Signature HMAC header) in wp-config.php.
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.