Hide submit button or lock form based on current logged-in user

Does anyone have an idea on how to “lock” a form based on a logged-in user role? Either disable all fields or simply hide the Submit button would work.

I have some fairly complicated forms that look better displayed as a form than a detail page, and it would save a ton of time to not have to re-create these (connected) pages.

@mdykstra, would you be able to provide an example of your form? Are you desiring to show already submitted information in a form (like an edit record form) or something else? The only way (and this is not 100%) to disable/validate any submission through form rules is to have a connection to the table the form would be pull/pushing information to. This could be done by a few fields like “Submitted by” and that would be tied to a user.

Alternatively, you may be able to work with a Pipe but I’ll defer to @tim.young, @Chem, or @moe for guidance on that.

Cheers,
Adam

1 Like

I would recommend doing it @SafetyUniversity’s way since its far more secure and is ‘server-side’ which makes it far safer.

Security concerns aside.

You can try this code:

TB.render('component_3', function (data) {

var role = '{loggedInUser.Role}';

if(role != 'Admins'){
    
    //This will make sure Enter Keyyboard key doesn't submit the form
    $(data.ele).find('form').unbind();
    
    //This will also disable the button
    $(data.ele).find('button').prop("disabled",true);
    
    //This will hide the button
    $(data.ele).find('button').hide();
 }    
});
1 Like