Hiding a ticket form from anonymous users

Answered

9 Comments

  • Pulkit Pandey
    Community Moderator
    Zendesk Luminary

    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

    0
  • Grace Mun

    Hey Pulkit Pandey, 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();
    }
    })
    1
  • Mark Rickard

    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.

    0
  • Zsa Trias
    Zendesk Customer Care

    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.

    0
  • Mark Rickard

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

    0
  • Mark Rickard

    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.

    0
  • Mark Rickard

    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

    0
  • Zsa Trias
    Zendesk Customer Care

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

    0
  • Mark Rickard

    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();
    }
    }
    );
    0

Please sign in to leave a comment.

Powered by Zendesk