Auto-populating fields in ticket forms with custom field input data
We're very close to where I need to be with customizing one of our ticket forms. We hide the Subject and Description and we're able to assign static values for them but we're looking to populate the fields with actual data being submitted in the form. Here is the code we are using:
var ticketForm = location.search.split('ticket_form_id=')[1];
var subject_value = "New Email Request for " + $("request_custom_fields_1111111").val();
if(ticketForm == 2222222) {
$('#request_subject').val(subject_value);
$('#request_description').val(subject_value);
$('#request_subject').parent('.request_subject').hide();
$('#request_description').parent('.request_description').hide();
};
When I submit the form with that code, the subject and description just say "New Email Request for " and does not include the custom field data which is part of the form being submitted. I've tried different variations from what I've seen online to include single quotes, input# and even brackets and sometimes I get "New Email Request for undefined" or "New Email Request for [object Object]".
Any help in solving this is greatly appreciated. Thank you.
-
Hey R. Bello,
While I can't assist with custom code on my end, I did want to share some documentation we have available that may help point you in the right direction:
- Using themes and templates to customize your Help Center
- Help Center CSS Cookbook
- Help Center Templates Introduction
- Help Center Javascript Cookbook
- Tips for using HTML to customize your Help Center
I'll also get this post added to our Community Roundup for August to help provide visibility to other users who may be able to offer up some guidance.
Cheers!
-
Hey,
In short I think you should change $("request_custom_fields_1111111").val(); to $("#request_custom_fields_1111111").val();
But this only takes the field value upon submit, which may throw errors if fields are required.
Other solution: set the field upon dropdown change.
I did this recently for a client of ours: When they select a dropdown, we set the subject field based on the choice.
https://support.cozie.be/hc/nl/requests/new?ticket_form_id=360000011197
Although the field is visible, the concept is the same.
In your case it would be something akin to:
//FORM ACTIONS
//Set form subject based on dropdown
$(document).on("change", "#request_custom_fields_360000077818", function() {
$("#request_subject").val(this.value)
}); -
Zendesk Support provided a link to this post:
and I was able to find the right code for it. It wasn't coded under $(document).ready(function(), it had to include a submit function, see below:
$(document).submit(function() {
var subjectstring1 = $("#request_custom_fields_1111111111").val();
if (window.location.href == "https://subdomain.zendesk.com/hc/en-us/requests/new?ticket_form_id=222222222"){
$('#request_subject').val("New Email" + " - " + subjectstring1); -
Can you remove subject and body/description for a single brand among several?
-
Hi Daniel,
In the request form you could do that yes.
Something likeif (window.location.href.indexOf("BRAND URL HERE") > -1) {
document.querySelector('.request_subject').style.display = "none";
document.querySelector('.request_description').style.display = "none";
document.querySelector('.request_description').style.display = "none";
}
Please sign in to leave a comment.
5 Comments