Skip to main content

tripetto_webhook filter

📖 Description

This filter is invoked right before form data is pushed to a configured webhook (more information about configuring webhooks in Tripetto here). It can be used to modify or enrich the data that is sent to the webhook endpoint. In most cases, you can include this hook in the functions.php file of your WordPress theme using the add_filter WordPress function.

danger

Make sure to specify the correct number of arguments for the 4th parameter accepted_args of the add_filter function. The number given there must match the number of parameters your filter function has!

Syntax

add_filter("tripetto_webhook", function($data, $form, $dataset) {
// Maybe modify $data in some way.

// What you return here, is what's sent to the webhook endpoint.
return $data;
}, 10, 3);

Parameters

NameTypeOptionalDescription
$dataobjectNoPHP JSON object that holds the form data in a name-value pair format. The object also contains the following information about the submitted response data and form:
- tripettoId: Identifier of the response data (can be used to retrieve the data from the tripetto_entries table) (number);
- tripettoIndex: Chronological index number of the response (number);
- tripettoCreateDate: Date and time of the response submission (string);
- tripettoFingerprint: Fingerprint hash of the form (string);
- tripettoFormReference: Reference of the form (can be used to retrieve the form from the tripetto_forms table) (string);
- tripettoFormName: Name of the form (string).
$formobjectYesPHP JSON object with form information. Contains the following fields:
- id: Contains the id of the form (number);
- reference: Contains the reference of the form (string);
- name: Contains the name of the form (string);
- fingerprint: Contains the fingerprint of the form (string);
- runner: Contains the name of the runner used for the form (string);
- created: Contains the date the form was created (string);
- modified: Contains the last modified date of the form (string).
$datasetobjectYesPHP JSON object that holds the form data and contains the following fields:
- id: Contains the id of the response (number);
- index: Contains the index number of the response (number);
- created: Date and time the response was received (string);
- fingerprint: Contains the fingerprint of the form (string);
- fields: Contains an array with all fields that are collected in the response. Each item in this array is of type IExportableField.
caution

If you have enabled the setting Send raw response data to webhook for a form, the $data parameter will be identical to the $dataset parameter. Since this is a setting that can be changed by the form editor, we recommend to always use the $dataset parameter for retrieving form data as this parameter always uses the same data format.

Example

add_filter("tripetto_webhook", function($data, $form, $dataset) {
// Add something to the data
$data->customField = "Test";

return $data;
}, 10, 3);

You don't have to return the $data argument. You can return something else, like a text string:

add_filter("tripetto_webhook", function($data, $form) {
return "This text string is now sent to the webhook endpoint instead of the data!";
}, 10, 2);

📁 Handling file uploads

If your form contains a file upload block or a signature block it is possible to use the uploaded file(s) in the tripetto_webhook filter. Files are uploaded to a special (protected) folder on your WordPress server. The meta information for each file (file name, path, etc.) is stored in the tripetto_attachments SQL table. To fetch the uploaded file, you should use the reference property of the field dataset. This reference can then be used to retrieve the file information from the tripetto_attachments table.

Example

add_filter("tripetto_webhook", function($data, $form, $dataset) {
global $wpdb;

// Let's assume the first field in the form dataset is a file upload
// Retrieve the reference so we can use it to find the file
$reference = $dataset->fields[0]->reference;

$file = $wpdb->get_row(
$wpdb->prepare("SELECT name,path from {$wpdb->prefix}tripetto_attachments where reference=%s", $reference)
);

if (!empty($file)) {
// Now the path to the file is available through $file->path
// The name of the file is available through $dataset->fields[0]->string or $file->name
}

return $data;
}, 10, 3);