Skip to content

Instantly share code, notes, and snippets.

@adczk
Last active September 2, 2025 08:24
Show Gist options
  • Select an option

  • Save adczk/a314ad50036ffd449147d28f2e876e2b to your computer and use it in GitHub Desktop.

Select an option

Save adczk/a314ad50036ffd449147d28f2e876e2b to your computer and use it in GitHub Desktop.
Forminator - simulate any 3rd party standard HTML form and send data as POST request to any URL, just like typical HTML form
<?php
/*
Forminator - send to eternal url like HTML form
This basically "emulates" any standard 3rd-party HTML form with Forminator
Example use - whenever you need to put standard HTML form on WP site but want to use/integrate Formiantor instead,
created for Capsule CRM initially (their "webform integration") but can be used practically with enything else
Tested with Forminator 1.17.1 - 1.24.6
by adamcz/WPMU DEV
USE AS MU PLUGIN
Config explained in comments
*/
add_filter( 'forminator_custom_form_submit_field_data', 'forminator_external_url_post', 10, 2);
function forminator_external_url_post( $field_data, $id ) {
### config below ###
$form_ids = array( 123 ); // ID of form(s) to push to external source; one or more, comma separated
$target_url = 'https://external-form-action-url_OR_webhook_url.com'; // URL to post data to
$do_json = true; // if to JSON encode data or not
// Map form fields to target fields;
// array element key is local form field ID
// array element value is remote field
$field_mapping = array(
'name-1' => 'FIRST_NAME',
'text-1' => 'DESC',
'date-1' => 'EVENT_DATE',
);
/* additional "hidden" data to send
modify to your needs; format is
array_key is "target" form field name
array_value is "target" form field value
*/
$fields_extra = array(
'FORM_ID' => '123',
'HIDDEN_MSG' => 'Hey! I am hidden field!',
);
#### END OF CONFIG; DON"T EDIT BELOW ###
$request_args = array(
'method' => 'POST',
'timeout' => 30,
);
$request_body = array();
if ( in_array( $id, $form_ids ) ) {
// loop through all submitted fields
foreach ( $field_data as $single_field) {
// loop through fields mapping
foreach ( $field_mapping as $field_local => $field_remote ) {
if ( $single_field['name'] == $field_local ) {
$request_body[$field_remote] = $single_field['value'];
}
}
}
// combine request settings, extra and body to single arg array
$request_args['body'] = array_merge( $fields_extra, $request_body );
// jsone encode if enabled
if ( $do_json ) {
$request_args['body'] = json_encode( $request_args['body'] );
$request_args['headers'] = array(
'Content-Type' => 'application/json',
'Content-Lenght' => strlen( $request_args['body'] )
);
}
// and POST data to remote service
$response = wp_remote_post( $target_url, $request_args );
// log response if debugging enabled
if ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ) {
error_log( print_r( $response, true ) );
}
}
// return unchanged field data
return $field_data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment