Gravity Forms | ADF/XML format - notification getting html tags

Author - Komal
20.11.2017
|
0 Comments
|

ADF XML FORMAT

ADF XML format stands for Auto-lead Data Format XML that is an automotive retailing industry standard data delivery format for import and export of automotive customer leads. This format is used as a way to format the customer data so that the heterogeneous systems can transmit and store data efficiently. In this, the email is sent in a particular xml pattern to the dealers from the customers.

For Example:

Suppose we have a Contact Form with only 4 fields- First Name, Last Name, Email , Message.

Then our ADF/XML format will be like:

<?xml version="1.0" encoding="UTF-8"?>
<?adf version="1.0"?>
<adf>
<prospect>
<form>{form_title}</form>
<requestdate>{date_mdy}</requestdate>
<customer>
<contact>
<name> {First Name:1} {Last Name:2}</name>
<email> {Email:3}</email>
<message> {Message:4}</message>
</contact>
</customer>
<vendor>
<contact>
<email>{admin_email}</email>
</contact>
</vendor>
</prospect>
</adf>

Adding this code will send the data in the adf xml format to the dealer which can be acceptable by all the systems.

ISSUE:  When we apply this notification and save it then on form submission we get notification like:

<html>
<head>
<title>Congrats! You have a new application to review.</title>
</head>
<body>
<?xml version="1.0" encoding="UTF-8"?>
<?adf version="1.0"?>
<adf>
<prospect>
<form>Contact Form</form>
<requestdate>07/09/2017</requestdate>
<customer>
<contact>
<name> Example Name</name>
<email> example@gmail.com</email>
<message>Can we have installments for this product?</message>
</contact>
</customer>
<vendor>
<contact>
<email>{admin_email}</email>
</contact>
</vendor>
</prospect>
</adf>
</body>
</html>

The issue is the extra HTML that is wrapping the XML. The text in yellow shows the html tags that gets attached to the notification automatically.

The reason behind this is that by default, gravity forms send notification emails as ‘Content-Type: text/html’. As some CRMs cannot handle the ‘html’ version of the lead so that causes the issue in their CRM.

Solution: To resolve this issue , we need to change the notification to ‘Content-Type: text/plain’ so that these html tags do not get attached to it and the CRMs can directly handle the XML formatted data. For this purpose, we need to add this code in child theme’s functions.php file and bind it with the notifications of the gravity form:

add_filter( 'gform_notification', 'change_notification_format', 10, 3 );  
function change_notification_format( $notification, $form, $entry ) {
if ( $notification['name'] == 'ADF/XML Format' ) { //insert ADF notification name
$notification['message_format'] = 'text';
return $notification;
} else {
$notification['message_format'] = 'html';
return $notification;}
}

Here ,add_filter( ‘gform_notification’, ‘change_notification_format’, 10, 3 );  

Will bind the function change_notification_format with notifications of gravity forms so that whenever a form will submit, this function will be called.

In the line if ( $notification[‘name’] == ‘ADF/XML Format’ ) , we need to write the name of the ADX/XML notification in place of “ADF/XML Format” for which we want to change the content type. It will change the notification to text-plain for a Specific Notification whose name will be given in the if condition here. For all the other forms, the content type will be HTML. So now, the notification will be without HTML tags i.e in plain text like this below image and CRMs can handle this.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *