Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chris-castillo-dev/034b5990a7d2a3b2875d904bdf72c648 to your computer and use it in GitHub Desktop.
Save chris-castillo-dev/034b5990a7d2a3b2875d904bdf72c648 to your computer and use it in GitHub Desktop.
/**
* Function to Send Bricks Form Data to Webhook
*/
function pro_bricks_form_to_webhook( $form ){
$data = $form->get_fields();
// The Bricks Form ID is the last part of the CSS ID
// So if a form has a CSS ID of bricks-element-fszxsr, then the form ID is fszxsr
$formId = $data['formId'];
// Replace this comment with the description of the form
// Copy and paste the IF block below to add custom action for other forms
if( $formId == 'fszxsr' ){
$curl = curl_init("https://some-web-hook-url-goes-here");
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($curl);
// Set result of action
if( !$result ){
$form->set_result([
'action' => 'my_custom_action',
'type' => 'danger', //or danger or info
'message' => esc_html__('Webhook failed', 'bricks'),
]);
}
}
}
add_action( 'bricks/form/custom_action', 'pro_bricks_form_to_webhook', 10, 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment