Hardcode description for different forms



投稿日時:2024年10月24日

Hi

I have 3 forms and would like each one to have a different hardcoded Description.

 

I have the following code already, but this is applied to all forms.

Is there a way to assign a different description by form ID or name similar to below?

 

 $('#request_description').val('System Access Form'); // Autofill description


0

3

3件のコメント

Hi John,
 
Thank you for your response. Thanks for clarifying! Since your form ID comes from the URL parameter ticket_form_id, you need to read that parameter from the URL, then set the description value based on it.
 
Here’s how you can do it with jQuery and vanilla JS:
 
$(document).ready(function() {
// Function to get URL params
function getUrlParameter(name) {
name = name.replace(/[\[\]]/g, '\\$&');
var regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)'),
results = regex.exec(window.location.href);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}

var formId = getUrlParameter('ticket_form_id');

var descriptionText = '';

if (formId === '123456789') {
descriptionText = 'Account Creation Form';
} else if (formId === '987654321') {
descriptionText = 'Account Decommission Form';
}

$('#request_description').val(descriptionText);
});
 
Please make sure this script runs after the form's HTML is loaded (e.g., inside $(document).ready() as above), and that the #request_description element exists on the page.
 

0


Hi - sorry for the late response. That doesn't seem to work for me. I took the Form ID from the URL of the form and entered into the code, but the tickets don't display the text I enter in the code.

 

An example of the URL where I get the firm id from is:  ‘https://test.zendesk.com/hc/en-gb/requests/new?ticket_form_id=123456789’

 

The code I used is below:

 

 if ($(""#request_issue_type_select").val() == "123456789") {Account Creation Form} else if ($("#request_issue_type_select").val() == "987654321") {Account Decommission Form} else { // Code to execute if neither condition is met (optional) // You can leave this empty if you don't need to handle the else case }

0


Hello, 

Yes it is possible to manipulate forms based on their id using the IF stateeent with the field id.

if ($("#request_issue_type_select").val() == "4632445424532") { // Your code for the first condition } else if ($("#request_issue_type_select").val() == "463242424532") { // Your code for the second condition } else { // Code to execute if neither condition is met (optional) // You can leave this empty if you don't need to handle the else case }

0


サインインしてコメントを残します。

お探しのものが見つかりませんか?

新規投稿