Last active
April 14, 2025 10:15
-
-
Save chris-castillo-dev/034b5990a7d2a3b2875d904bdf72c648 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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