Hiding a ticket form from anonymous users | Community
Skip to main content

Hiding a ticket form from anonymous users

  • January 9, 2023
  • 9 replies
  • 0 views

Grace16

Is there a way to restrict a specific ticket form from being visible to anonymous users i.e. Help Center visitors who are not signed in? We have different personas accessing our public Help Center and ideally, this specific form is not available from the drop-down field on the new request page unless they're signed in. 

I've seen the other Community posts where you can restrict form viewing permissions based on the organization name or user tags, and how you can restrict the "submit a request" button entirely, but unfortunately, none of these existing posts solve this specific use case. 

9 replies

Pulkit12
  • January 10, 2023

Hi Grace Mun

Please, add the below code at the bottom of your script.js file 

  function DisableSubmitaRequestbutton(){
    if (HelpCenter.user.role=="anonymous"){
      document.querySelector(".submit-a-request").classList.add("hide");
        }
  }
  DisableSubmitaRequestbutton();

Let me know if it solves your issue 

Thank You

Pulkit

Team Diziana


Grace16
  • Author
  • January 13, 2023

Hey @pulkit12, would this code block anonymous users from submitting a request in general? 

We still want anonymous users to be able to submit a request, there's just a specific form we want to hide from them. 

I've set up the code below and it seems to work actually:

//To hide a form from anonymous users
jQuery( document ).ready(function() {
if (HelpCenter.user.role=="anonymous"){
var tagsToRemove = ['insert form ID'];  
function removeTagsWeDontWant() {
$('.nesty-panel').on('DOMNodeInserted', function(e){
for(var i in tagsToRemove) {
$('li#' + tagsToRemove[i]).remove();
}
});
};
removeTagsWeDontWant();
}
})

Mark28
  • July 21, 2023

We want to hide 9 of 10 forms from anonymous users. What is the syntax to list multiple form IDs in this code?

Thanks in advance! This is a beautiful thing.


Zsa
  • July 24, 2023

Hello Mark,

The custom code seems to be provided by one of our community members. 
I have implemented the same code on my test account, adding multiple form IDs thru this line:

var tagsToRemove = ['formID1', 'formID2', 'formID3']; 

However, please do note, we're unable to guarantee that it will continue to function as the product changes.


Mark28
  • July 24, 2023

Thank you for the assist. I will use it gladly for as long as I can.


Mark28
  • July 24, 2023

Would the jquery referenced above go in the script.js file or on the new request page? I added the script to the script.js file, adjusted for multiple forms to block from anonymous sight, and published it, and I don't see that it's working.


Mark28
  • July 24, 2023

Never mind! I forgot to add the jquery script to the document_head file.

https://support.zendesk.com/hc/en-us/articles/4408829274906-Importing-or-upgrading-jQuery


Zsa
  • July 25, 2023

Awesome! Glad you're able to figure this out, Mark!


Mark28
  • November 6, 2023

This has stopped working for me and I can't tell if changes to Zendesk have broken it. I'm using the Diziana Makem theme, Theme version 3.1.2, Templating API v1. I've added jQuery 3.6.1 to the script.js file, made sure the form IDs below are correct, and added the following code to my document_head file:

//Hide forms from anonymous users
jQuery( document ).ready(function()  {
if (HelpCenter.user.role=="anonymous"){
var tagsToRemove = ['1260815258330', '1900004317724', '13506320793243', '1260815256470', '1900004317704', '13528765623707', '5308706681371', '5073802798235', '1260815252470', '1900004315784', '17932684959515', '17932846343067', '17932966253339', '18224882477211', '17932893585691'];  
function removeTagsWeDontWant() {
$('.nesty-panel').on('DOMNodeInserted', function(e){
for(var i in tagsToRemove) {
$('li#' + tagsToRemove[i]).remove();
}
});
};
removeTagsWeDontWant();
}
}
);