General developer forum

force users to complete custom profile fileds when login

 
Picture of Ali Rajabpour Sanati
force users to complete custom profile fileds when login
 

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: -
Picture of Rob Bright
Re: force users to complete custom profile fileds when login
 

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: -
Picture of Ali Rajabpour Sanati
Re: force users to complete custom profile fileds when login
 

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

 
Average of ratings: -
Picture of Ali Rajabpour Sanati
Re: force users to complete custom profile fileds when login
 

Please somebody help mesad

 
Average of ratings: -
Picture of Ali Rajabpour Sanati
Re: force users to complete custom profile fileds when login
 

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

 
Average of ratings: -
Picture of Mr. Marc
Re: force users to complete custom profile fileds when login
 

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

 
Average of ratings: -
Picture of Michael E
Re: force users to complete custom profile fileds when login
 

Ali,

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

 

Thanks,

Michael

 
Average of ratings: -
Picture of Michael E
Re: force users to complete custom profile fileds when login
 

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 (2)
Picture of David Hempy
Re: force users to complete custom profile fileds when login
 

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.
       )       
    );

 
Average of ratings: -
Ben Ellis - chilled ;)
Re: force users to complete custom profile fileds when login
 

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.







 
Average of ratings: -
Picture of Olumuyiwa Taiwo
Re: force users to complete custom profile fileds when login
Group Particularly helpful Moodlers

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.

 
Average of ratings: -
Just wondering . . .
Re: force users to complete custom profile fileds when login
Group Particularly helpful Moodlers
OK,voted.

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

-Derek

 
Average of ratings: -
Picture of Olumuyiwa Taiwo
Re: force users to complete custom profile fileds when login
Group Particularly helpful Moodlers

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?

 
Average of ratings: -
Picture of Kane Davis
Re: force users to complete custom profile fileds when login
 

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.

 
Average of ratings: -
Picture of Rocky Knowledge
Re: force users to complete custom profile fileds when login
 

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

 
Average of ratings: -
Picture of Mathias Chouet
Re: force users to complete custom profile fileds when login
Group Plugin developers

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)
Picture of Albert Leatherman
Re: force users to complete custom profile fileds when login
 

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

 
Average of ratings: -
Picture of Mathias Chouet
Re: force users to complete custom profile fileds when login
Group Plugin developers

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)
Picture of Dave Emsley
Re: force users to complete custom profile fileds when login
Group Particularly helpful Moodlers

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

 
Average of ratings: -
Picture of Mathias Chouet
Re: force users to complete custom profile fileds when login
Group Plugin developers

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 (1)