Sending Bricks Builder Forms Data From WordPress To Airtable

WordPress snippet for Bricks Builder that sends all form fields data to Airtable using a webhook.

This is a custom function in PHP that hooks into the “bricks/form/custom_action” action in WordPress. The function takes one parameter, a form object, and retrieves the fields of the form using the “get_fields” method. It then sets a variable “webhook_url” to a specific URL, and creates an argument array that includes the fields of the form as the body. The function then makes a remote post request to the specified URL using the WordPress function “wp_remote_post” and the arguments array. Finally, the function sets a result for the form, with an action, type, and message specified.

<?php
function my_form_custom_action( $form ) {
   
  $fields = $form->get_fields();
  // $formId = $fields['formId'];
  // $postId = $fields['postId'];
  // $settings = $form->get_settings();
  // $files = $form->get_uploaded_files();
 
  // Perform some logic here...
  $webhook_url = 'https://YOUR-WEBHOOK-URL-GOES-HERE';
 
  $args['body'] = $fields;
  $response = wp_remote_post($webhook_url, $args);

  // Set result in case it fails (if needed)
  $form->set_result([
    'action' => 'my_custom_action',
    'type'    => 'success', //or danger or info
    'message' => esc_html__('Oh my custom action failed', 'bricks'),
  ]);
}

add_action( 'bricks/form/custom_action', 'my_form_custom_action', 10, 1 );

 

Leave the first comment