Displaying User Field For Ease in HTML Code Block

Displaying User Field For Ease in HTML Code Block

by Seth Mengal -
Number of replies: 10

Hi, i want to show the Custom User Field in an HTML Box, What should i write for the code. Any reference and tut would be great.

Basicly its the third party website username/password for each indiviual student. As the students are young, i thought of placing it for the users for ease.

Attached Image: I would love to show the highlighted field for the users!

Cheerss!!!!

Attachment StudentInfo.png
La media da valetaziuns: -
In reply to Seth Mengal

Re: Displaying User Field For Ease in HTML Code Block

by Gareth J Barnard -
Maletg da 	Core developers Maletg da 	Particularly helpful Moodlers Maletg da 	Plugin developers

Dear Seth,

The file '/user/profile.php' has the code:

/// Print the Custom User Fields
profile_display_fields($user->id);

which is defined in '/user/profile/lib.php'.  But as it is php you may have to create a custom block rather than use a HTML block with the 'php' tag as that I imagine would be stripped out because of possible script injection.

Cheers,

Gareth

La media da valetaziuns: -
In reply to Gareth J Barnard

Re: Displaying User Field For Ease in HTML Code Block

by Seth Mengal -

Oh okay thats great. Ill have a look. The custom box functions same as the html box yeh? 

 

La media da valetaziuns: -
In reply to Seth Mengal

Re: Displaying User Field For Ease in HTML Code Block

by Gareth J Barnard -
Maletg da 	Core developers Maletg da 	Particularly helpful Moodlers Maletg da 	Plugin developers

As far as I know, but I've never created a custom block from scratch.

La media da valetaziuns: -
In reply to Gareth J Barnard

Re: Displaying User Field For Ease in HTML Code Block

by Seth Mengal -

Hi Gareth, i tried searching for custom box tut, but i cannot find a good tutroial over the internet :/

La media da valetaziuns: -
In reply to Seth Mengal

Re: Displaying User Field For Ease in HTML Code Block

by Gareth J Barnard -
Maletg da 	Core developers Maletg da 	Particularly helpful Moodlers Maletg da 	Plugin developers

Dear Seth,

There is the developer documentation on creating a new block http://docs.moodle.org/dev/Blocks and you could pose the question on the blocks forum of how you would call the user profile code from within a block or if you needed to create your own.

Cheers,

Gareth

La media da valetaziuns: -
In reply to Gareth J Barnard

Re: Displaying User Field For Ease in HTML Code Block

by Seth Mengal -

Thanks alot guys!!!!

I got it done on the Logged in user, and added the custom fields below the block predefined there :D

 

ilovemoodle :D

Attachment Image 7.png
La media da valetaziuns: Useful (1)
In reply to Seth Mengal

Re: Displaying User Field For Ease in HTML Code Block

by Wasim Fadloun -

Can you please guide me how did you add the custom fields below the block predefined

 

thanks

La media da valetaziuns: -
In reply to Wasim Fadloun

Re: Displaying User Field For Ease in HTML Code Block

by Gareth J Barnard -
Maletg da 	Core developers Maletg da 	Particularly helpful Moodlers Maletg da 	Plugin developers

Hi Wasim,

I don't know how Seth did it, but it might be worth a message to him to ask.

Cheers,

Gareth

La media da valetaziuns: -
In reply to Wasim Fadloun

Re: Displaying User Field For Ease in HTML Code Block

by Richard Oelmann -
Maletg da 	Core developers Maletg da 	Particularly helpful Moodlers Maletg da 	Plugin developers Maletg da 	Testers

First of all you need to create the custom profile fields for your users

Administration > Users > Accounts > User Profile fields

and you can then load the content of the field wherever you need it as:

require_once("$CFG->dirroot/user/profile/lib.php");
profile_load_custom_fields($user);

echo $user->profile['yourcustomprofilefieldshortname']

HTH

Richard

La media da valetaziuns: Useful (1)
In reply to Wasim Fadloun

Re: Displaying User Field For Ease in HTML Code Block

by Ajeet Kumar -

Hi Wasim,

you can add following code in the myprofile block to display custom user profile filelds

$user_profile_field_rec = profile_user_record($USER->id);
$this->content->text .=$user_profile_field_rec->profilefield1;
$this->content->text .=$user_profile_field_rec->profilefield2;

La media da valetaziuns: -