Wordpress | Dynamically generating ADF XML format of the form submission

Author - Komal

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. DYNAMICALLY GENERATING ADF XML FORMAT OF THE FORM SUBMISSIONIn this, the email is sent in a particular pattern to the dealers from the customers.

For Example:
Suppose we have a gravity form:
0401
Then we can add this below code in the message of the form notification in settings of that form as shown in the image below:
0402

<?ADF VERSION "1.0"?>
<?XML VERSION “1.0”?>
<adf>
<prospect>
<form>{form_title}</form>
<requestdate>{date_mdy}</requestdate>
<customer>
<contact>
<name>Name: {First Name:1} {Last Name:2}</name>
<email>Email: {Email:3}</email>
<phone>Phone: {Phone:4}</phone>
<message>Message: {Message:5}</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.

Example Output email content:

But sometimes we need to dynamically generate the adf xml format so that even if the new field is added to the form or deleted from the form, we need not change this above code of the form and the adf xml format can be generated according to the fields present in the form.

So this can be done by adding this below code in the functions.php file of the theme:

add_filter('gform_notification_1', 'form_notification', 10, 3);
function form_notification($notification, $form, $entry) {
$messageText = '
< form >{
form_title
} < /form>          
{date_mdy}'; $i=1; $str=''; foreach($entry as $element){ $str.="\n"."<element".$i.">".$entry[$i].""; $i++; }                   $temp="{admin_email} < pre > ";
$notification['message'] = $messageText.$str.$temp;
return $notification;
}

This code will check for all the fields of the form dynamically and will generate adf xml format of them to be sent to the dealer.
Use your own form number in place of gform_notification_1. Example if your form’s id is gform_5 then you will add it as add_filter(‘gform_notification_5’, ‘form_notification’, 10, 3);
In this way you can bind this function to as many gravity forms as you want.

For Example:

/* for ADF XML format of the form submission */
add_filter('gform_notification_8', 'form_notification', 10, 3);
add_filter('gform_notification_5', 'form_notification', 10, 3);
add_filter('gform_notification_2', 'form_notification', 10, 3);
add_filter('gform_notification_7', 'form_notification', 10, 3);
add_filter('gform_notification_4', 'form_notification', 10, 3);
add_filter('gform_notification_1', 'form_notification', 10, 3);

function form_notification($notification, $form, $entry) {
$messageText = '
< form > {
form_title
} 
< /form>{date_mdy}'; $i=1; $str=''; foreach($entry as $element){ $str.="\n"."<element".$i.">".$entry[$i].""; $i++; } $temp="{admin_email} < pre > ";
$notification['message'] = $messageText.$str.$temp;
return $notification;
}
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 *