Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ricardovf/b09a7c2297a31c890467b02cfc72a3d2 to your computer and use it in GitHub Desktop.
Save ricardovf/b09a7c2297a31c890467b02cfc72a3d2 to your computer and use it in GitHub Desktop.
Pre-populate Zendesk new ticket fields via query params
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]) );
}
}
});
// build your data
var field_data = {
"anonymous_requester_email": "", // email
"subject": "", // subject
"description": "that shit cray", // description
"custom_fields_23823917": "", // your name
"custom_fields_23823947": "bit_module_wire__orange___cloudbit" // which module [cloudBit]
}
// 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 = 'https://support.littlebits.cc/hc/en-us/requests/new?ticket_form_id=28986&'
var redirect_url = zd_url + q.join('&')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment