-
-
Save ricardovf/b09a7c2297a31c890467b02cfc72a3d2 to your computer and use it in GitHub Desktop.
Pre-populate Zendesk new ticket fields via query params
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) ); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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