Merge Multiple Form Fields Into a Hidden Field to Map Multiple Formyoula Fields to a Single Salesforce Field
In this guide, we will explain how to merge multiple Formyoula form fields and submit the value into a single field on your Salesforce record.
1. Please add the necessary fields on your form that will be used for the merge.
2. Please drag and drop a Hidden field on the form.
3. Please edit the Hidden field and add the necessary field labels in double curly brackets. Please make sure to use the exact field labels. For example:
{{First Name}} {{Last Name}} {{Age}}
4. Please drag and drop a JavaScript element on the form.
5. Please edit the JavaScript element and add the following code:
// Get hidden field
var hidden_field = window.formyoula.form_fields[ 'Hidden Field' ];
// Set static value for mergesvar
hidden_field_value = hidden_field.get( 'value' );
// Get all merge fields based on a hidden field valuevar
merge_fields = _.uniq( hidden_field_value.match( /[^{{}}]+(?=\})/g ) );
// Look Through all merge fields and tag elements we want to observe to reevalueate the value
for ( var i = 0; i < merge_fields.length; i++ ) {
// Check if merge field matches any component
if ( window.formyoula.form_fields[ merge_fields[ i ] ] ) {
// Listen to merge field changes
window.formyoula.form_fields[ merge_fields[ i ] ].on( 'all', function() {
// Metrge values
resolve_merge_fields();
} );
}
}
// Resolve merge fields on page
loadresolve_merge_fields();
// Main merge function
function resolve_merge_fields() {
// Set hidden field value
var merged_value = hidden_field_value;
// Get merge field values
for ( var i = 0; i < merge_fields.length; i++ ) {
// Get value from component
var value = window.formyoula.form_fields[ merge_fields[ i ] ] ? window.formyoula.form_fields[ merge_fields[ i ] ].get( 'value' ) : '';
// Replace Expression Merge Fields With Field Values
merged_value = merged_value.replace( new RegExp( '{{' + merge_fields[ i ] + '}}', 'g' ), value );
}
// Save merged value
hidden_field.set( {
value: merged_value
} );
}
6. Please save and close the form.
7. Please map the Hidden field to the necessary Salesforce field on your desired Object.
8. Now, once you submit a form entry with all the fields, they will be merged into a single field in Salesforce.
Form Submission:
The field in Salesforce:
If you have any questions, please let us know by sending an email to support@formyoula.com