force users to complete custom profile fileds when login

force users to complete custom profile fileds when login

by Ali Rajabpour Sanati -
Number of replies: 21

hello everybody,

i have created some custom profile fileds, but i don't know how to make all registered users to complete the fields as soon as they log in to moodle...

thank you in advanced

Average of ratings: -
In reply to Ali Rajabpour Sanati

Re: force users to complete custom profile fileds when login

by Rob Bright -

If you are logged in as admin, go to: Site administration -> Users -> Accounts -> User Profile Fields -> Create a new profile category and choose what kind of input the users should add, either a checkbox, date/time, menu of choices, text area or text input. Then when you scroll down, there is an option "Is this field required?". Change this to yes, then users must enter this data when they register on the site.

Average of ratings: Useful (1)
In reply to Rob Bright

Re: force users to complete custom profile fileds when login

by Ali Rajabpour Sanati -

thank you for ur sharp reply, but i want users which are already registered complete the fields...!

In reply to Ali Rajabpour Sanati

Re: force users to complete custom profile fileds when login

by Ali Rajabpour Sanati -

Please somebody help mesad

In reply to Ali Rajabpour Sanati

Re: force users to complete custom profile fileds when login

by Ali Rajabpour Sanati -

guys please help me change the moodle required fileds to force all already registred users to complete custom profile fileds...

In reply to Ali Rajabpour Sanati

Re: force users to complete custom profile fileds when login

by Mr. Marc -

is there a way to force all users to have a certain student profile picture and instructors to have a different one?

In reply to Ali Rajabpour Sanati

Re: force users to complete custom profile fileds when login

by Michael E -
Picture of Core developers Picture of Testers

Ali,

I'm wondering if you ever found a solution for that. I would like to accomplish the same thing.

 

Thanks,

Michael

In reply to Michael E

Re: force users to complete custom profile fileds when login

by Michael E -
Picture of Core developers Picture of Testers

I just found the answer myself.

    1. Open the file lib/moodlelib.php
    2. Search for: function user_not_fully_set_up($user) {(approx. line 3383)
    The complete function looks like this:
    function user_not_fully_set_up($user) {
        if (isguestuser($user)) {
            return false;
        }
        return (empty($user->firstname) or empty($user->lastname) or empty($user->email) or over_bounce_threshold($user));
    }
    3. Edit the return string according to your needs. Use the shortname of the field you want to force users to fill in. The correct usage is: empty($user->profile['short_fieldname'])
    If the fieldname for example is managersemail (from the Face-to-Face mod), change the return string to:

return (empty($user->firstname) or empty($user->lastname) or empty($user->email) or empty($user->profile['managersemail']) or over_bounce_threshold($user));

Hope that helps!

Average of ratings: Useful (3)
In reply to Michael E

Re: force users to complete custom profile fileds when login

by David Hempy -

Thank you, Michael!  I just implemented this on our 2.5 server

I added a permissions check to only require the extra fields from students (not admins, teachers, etc.).  That part kinda works, but has issues since students are difficult to detect outside of a course.  I'm going to tinker with it some more later, but here's a start if anyone else wants to pursue it.

    return (empty($user->firstname) or empty($user->lastname) or empty($user->email) or over_bounce_threshold($user)
       or (
           (    empty($user->profile['BirthMonth'])
             or empty($user->profile['BirthDate'])
             or empty($user->profile['BirthYear'])  
           ) and !has_capability('report/courseoverview:view', context_system::instance())  // Allows teacher to avoid required birthdate.
       )       
    );

In reply to David Hempy

Re: force users to complete custom profile fileds when login

by Benjamin Ellis -
Picture of Particularly helpful Moodlers

Maybe we should ask for it as a new feature in tracker as I find myself facing the same issue.  

I am against hacking Moodle core code so I am intending to develop a plugin e.g. block that will direct the user to providing the information though I doubt I could force them to provide the info.  If anyone can think of a way to, I will gladly use listen.







In reply to Benjamin Ellis

Re: force users to complete custom profile fileds when login

by Olumuyiwa Taiwo -
Picture of Plugin developers

I'm also against hacking core code, so I've created MDL-46946 to track this issue. Please vote for it if you want it fixed.

In reply to Olumuyiwa Taiwo

Re: force users to complete custom profile fileds when login

by Derek Chirnside -
OK,voted.

I think you should comment on the code to say the code snippet is here.

-Derek

In reply to Derek Chirnside

Re: force users to complete custom profile fileds when login

by Olumuyiwa Taiwo -
Picture of Plugin developers

Derek, I'm not quite sure what you mean by "comment on the code" since the function concerned is fairly short and I've already mentioned that it's in /lib/moodlelib.php. Can you please clarify?

In reply to Olumuyiwa Taiwo

Re: force users to complete custom profile fileds when login

by Kane Davis -

its possible to do this with a custom auth provider. its a little hackish but it beats modifying core. just act on the user authenticated hook and force a redirect to the profile edit page. 

sorry for the latish reply; i just had a client ask for this functionality last week.

In reply to Michael E

Re: force users to complete custom profile fileds when login

by Rocky Knowledge -

Hi Michael, 

I've tried to force update profile on Moodle 3.0.3 by your trick, but moodel return me an exception:

Default exception handler: L'accesso al corso o attivit\xc3\xa0 non \xc3\xa8 consentito. Debug: User not fully set-up

Error code: requireloginerror, referer: http://192.168.3.135/moodle/user/edit.php

* line 2621 of /lib/moodlelib.php: require_login_exception thrown, referer: http://192.168.3.135/moodle/user/edit.php

* line 44 of /lib/editor/atto/autosave-ajax.php: call to require_login(), referer: http://192.168.3.135/moodle/user/edit.php

Can you help me?

Thanks

RK

In reply to Ali Rajabpour Sanati

Re: force users to complete custom profile fileds when login

by Mathias Chouet -

Hi,

Although it does not exactly address the (old) OP's demand, I'm developing a block that suggests users to complete their profile.

https://github.com/telabotanica/moodle-block_completeyourprofile

It is very simple at the moment : this block checks if all required "profile fields" (admin > users > accouts > profile fields) are filled for the current user; if not, suggests him to complete the profile.

Only fields that are both required and visible are considered (I'll try to make this configurable). It will soon be submitted to Moodle plugins repository. Any feedback is appreciated.

Thanks, greetings,

Mathias

Average of ratings: Useful (1)
In reply to Mathias Chouet

Re: force users to complete custom profile fileds when login

by Albert Leatherman -

Great, I would find this very useful, Matias. Please keep us posted. Thanks.

In reply to Albert Leatherman

Re: force users to complete custom profile fileds when login

by Mathias Chouet -

Hi Albert,

The plugin is now configurable : you can decide whether non-mandatory fields are taken in account or not.
All messages are configurable, too.

I'm still confused with how to declare a plugin to Moodle's repository - many weeks after registering it, still no news mixed
But the GitHub version should work (works on a production site using Moodle 3.0).

Any feedback is very appreciated, thanks for your interest.

Greetings,

Mathias

Average of ratings: Useful (2)
In reply to Mathias Chouet

Re: force users to complete custom profile fileds when login

by Dave Emsley -

Hi Mathias,

Great block, thanks.  This does EXACTLY what is needed.  I love the fact that if all is completed then the block does not appear AT ALL - that's a great touch.


Cheers


Dave

In reply to Dave Emsley

Re: force users to complete custom profile fileds when login

by Mathias Chouet -

Hi Dave.


Glad to read that this plugin does what you needed, thanks for your message.

The plugin is now officially available here : https://moodle.org/plugins/block_completeyourprofile


Greetings,

Mathias


Average of ratings: Useful (2)
In reply to Mathias Chouet

Re: force users to complete custom profile fileds when login

by Dom F -

Hi Mathias

I have found my way here because as a Moodle 2.7 user I was pretty shocked and mortified to find that those of us using Moodle 2.7 (and believe me I have good reasons if you've seen my website!) have sort of been abandoned with the fix only available to Moodle 3.x

Can I confirm the following?

1. Does your module work in Moodle 2.7? (if not then am I truly screwed?)

2. Does it fix this glaring error in the core code by popping up a window on the users PROFILE PAGE only - or somewhere else? 

3.Does it "invite" the user to complete all the required registration info they missed due to this nasty bug - OR is it just a nag - or compulsory or something else. (I ask as my experience is that unless its compulsory most people dont bother with their profile page - they are called teachers and students)

Do let me know, I'm not a happy camper that Moodle 2.7 users are orphaned by the decision not to support the fix in this version.

In reply to Dom F

Re: force users to complete custom profile fileds when login

by Mathias Chouet -

Hi Dom,

Not sure that I correctly understood your questions, here are a few answer elements.

1. I have no idea if complete_your_profile works with Moodle 2.7, I didn't test smile sorry about that. But it should, as it involves only simple mechanisms (a few SELECT in the database).

2. Unfortunately it doesn't fix any core code, it's just a plugin that adds more code.

3. This block shows a message and a button in the block region where you added it. The button takes the user to his/her profile page and does nothing more. Unless the profile page is "complete" (according to the block options you chose), the message and button will keep appearing. But it doesn't force the user, it just suggests/advises to complete their profile.

Hope I answered your questions,

Greetings,

Mathias