Get moodle user in the add template

Get moodle user in the add template

by Carlos Vereda -
Number of replies: 2

Hello

Is it possible to get the moodle user that is filling the fields of a database?. The tag "## user ##" allow that in the list template, but I cann't get the user in the add template. The aim is the selection of fields that will be shown in the View Add, depending on the moodle user. If the moodle user is known, a javascript will hide the selected fields using "window.onload = FunctionHideFields;". FunctionHideFuelds selects the fields that will be hidden to the user.

Thanks


Average of ratings: -
In reply to Carlos Vereda

Re: Get moodle user in the add template

by William Lu -
Picture of Particularly helpful Moodlers

Hi Carlos,

I guess you are asking for the same thing as in the previous post:

https://moodle.org/mod/forum/discuss.php?d=361864

In reply to William Lu

Re: Get moodle user in the add template

by Carlos Vereda -

Thank you for the link, but unfortunately my institution did not installed the Dataform plugin.

I think I have got a solution. The html code of the "View Add" contents a span tag using a class named "usertext". The text inside that span tag is just the name of logged user. So, I can get the name of the logged user by the following java script:

var LoggedUser = document.getElementsByClassName('usertext')[0].textContent;

Now I can hide/show the fields that LoggedUser is allowed to see.

smilesmilesmile