Webhook: Receiving Form Submissions to Custom Scripts

Use webhooks, a system of automated notifications, to receive form submissions to custom scripts. Captured data will be delivered to you via POST.
To activate Webhook, go to the Site Settings → Forms → Webhook.
Enter the address of your script. If it is necessary to send cookies, select the checkbox. Save the changes.
Note: The link to the script must be available, and the script must respond within five seconds. Otherwise, the data won't be sent, and the system will make two more attempts to send it, one attempt per minute.
Note: your script must use secure HTTPS protocol.
Go to the page and select the "WEBHOOK" checkbox in the Content panel of the form block.

Click "Save and close", then publish the page. When someone fills out the form, the data will be sent via POST to the address of the script that you have specified in the Site Settings.
A sample of a script to send submissions to your email
Place the script on your server and add its address to the Webhook settings. After that, you will start receiving captured data by email.

<?php

header('Access-Control-Allow-Origin: *');

$headers = "From: from@webhookservesite.com";​ 
/* change this sample email address to the valid email that you would like to receive letters from  */
​
 $message = print_r($_POST,true);
 @mail('to@mail.com', 'Tilda TEST', $message, $headers);
/* change this sample email address to the valid email that you would like to receive submissions to  */

echo"ok";

?>
Product data transferring
In the Webhook service settings, you can find additional settings for transferring product data to the script: Transferring product data in the order in arrays and transferring externalid (external code) from other systems.
The externalid checkbox is only available if you select the option of transferring product data as arrays. If you select it, the externalid of the product in the Catalog is transferred to connect this product to the external system.
How to get more information and retrieve variables in PHP
To retrieve data from all fields and values without changes, you need to access the $_POST variable. $_POST is an associative array, for example:

Email=test%40email.com 
Name=test+name 
Phone=0123456789 
Comments=example+comment 
Selectbox=red 
Checkbox=yes 
Date=25-03-2017 
Time=17%3A59 
Quantity=124 
Url=website.com
To retrieve information about a particular field, you need to access the array element by name, such as $_POST["Date"], where "Date" is a variable name that has been specified in the form field.

If you want to add your comments to the fields, you can use this example to do so:

<?php

header('Access-Control-Allow-Origin: *');

$headers = "From: from@webhookservesite.ru";​

$message = "";

foreach($_POST as $key => $value) {
  if($key == "Date") {
    $message .= "Hotel check out date"; 
  } else { 
    $message .= $key; 
  }
  $message .= ": " . $value . "\n"; 
} 

$message = ​print_r($message, true);

@mail('to@mail.com', 'Tilda TEST', $message, $headers);

echo "ok";

?> 
If you don't change the fields' variable names, you will retrieve the information related to the field names that have their first letters in uppercase.

If you have set a different variable name for a particular field, the information you retrieve from it will look like this:

customnamefield=yellow
In addition to the form fields' data, you can also retrieve the following data:

tranid=467251%3A8442970
formid=form48844953
where "tranid" refers to the Lead ID (a unique lead number) from the "Leads" section and "formid" refers to the Block ID (the unique number of the block that was used for data submission).

Some characters will be replaced before form responses are transferred, e.g., the "@" sign will be replaced with "%40", the colon sign (":") will be replaced with "%3a." To decode these characters, you can use the urldecode function. (https://www.php.net/manual/en/function.urldecode.php).

How to retrieve the address from which the form response has been submitted

You can access the $_SERVER["HTTP_REFERER"] variable to retrieve the address from which the form response has been submitted via a webhook.

How to get a cookie file (optional)

Select the "Send cookies" checkbox in the Webhook settings if you want the form to include the COOKIES field whenever there is a cookie file, for example:

COOKIES=_ga%3DGA1.2.1861016115.1519204131%3B+_ym_uid%3D2021810468765220932 

Please note that you will receive no cookie file with the form response if the user has never visited your website before. If the user visited a web page with a UTM tag and returned to the website no later than 30 days after that, the cookie file will include UTM parameters, for example:

COOKIES=TILDAUTM%3Dutm_source%253Dyandex%257C%257C%257Cutm_medium%253Dcpc%257C%257C%257Cutm_campaign%253Dpromo%257C%257C%257Cutm_content%253Dblocktext%257C%257C%257Cutm_term%253Dpoisk%257C%257C%257C 

You can use the following services to check how the fields' data coming from the form responses looks like:
http://requestcatcher.com
https://webhook.site
Note: Unfortunately, the Tilda support team does not assist with questions related to custom codes.
Made on
Tilda