Skip to content

Instantly share code, notes, and snippets.

@mgdiez
Last active November 20, 2018 14:36
Show Gist options
  • Save mgdiez/030d8c7c491382b2a54e3f6dd4151ed2 to your computer and use it in GitHub Desktop.
Save mgdiez/030d8c7c491382b2a54e3f6dd4151ed2 to your computer and use it in GitHub Desktop.
Zendesk populate fields
var field_data = {
"anonymous_requester_email": "", // email
"subject": "", // subject
"description": "that shit cray", // description
"custom_fields_XXXXXXX": "", // your custom field
}
// parse it out for our url format
var q = []
for ( var k in field_data ) {
if (field_data.hasOwnProperty(k)) {
q.push('request_fields[' + k + ']=' + encodeURIComponent(field_data[k]) )
}
}
// wrap it up
var zd_url = 'url here'
var redirect_url = zd_url + q.join('&')
jQuery(function($) {
if ( !$('#new_request') ) return
var query = window.location.search.substring(1);
var vars = query.split("&");
var match, fieldID;
for (var i=0; i<vars.length; i++) {
var pair = vars[i].split("=");
match = pair[0].match(/^request_fields\[([a-z_\d]+)\]$/)
if (match) {
fieldID = match[1];
$('#request_' + fieldID).val( decodeURIComponent(pair[1]) );
}
}
});
jQuery(function($) {
if ( !$('#new_request') ) return
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0; i<vars.length; i++) {
var pair = vars[i].split("=");
$('#request_'+ pair[0]).val(decodeURIComponent(pair[1]));
}
$('.form-field.string.optional.request_custom_fields_360000382359').hide()
$('.form-field.string.optional.request_custom_fields_360000357665').hide()
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment