Auto enrolling after signup

Auto enrolling after signup

by Phil Coultier -
Number of replies: 3

Hi everyone,  I've been trying to figure out how to enrol people on a course automatically once they create an account.

I've done it before, many years ago by adding this line of code to the login/signup_form.php file:

$mform->addElement('hidden', 'courseselected', 58);

where 58 is the course ID of the course to auto-enrol the student on.

 

however, i've returned to it and can't seem to get it working again.

 

Any ideas?

Average of ratings: -
In reply to Phil Coultier

Re: Auto enrolling after signup

by Kenny McCormack -

Hi Phil,

I have a similar requirement for a Moodle setup.

My requirement is:

1 - user creates new account on the site using self-reg

2 - user is enrolled on all courses on the site i.e. they are authenticated user but enrolled on courses automatically and would be graded

Enrollment on all courses should be "silent" and any new course created on the site they also become enrolled on it automatically.

I think this might have been possible in 1.9+ but not to sure on 2.0+ although there is a settting in Grades > General Settings allows the Auth User to be graded

Anything that can be done without changing core code would be best - though it may come down to a CRON

Any help or suggestions would be appreciated


Best Regards

 

In reply to Phil Coultier

Re: Auto enrolling after signup

by Scott Krajewski -

Hi Phil,

I think I found a way that works.  I'm using moodle 2.0.2.  This seems to work on my test server and a production server.   I add the enrollment to the confirmation step as I believe the user needs to be confirmed before they can be enrolled. 

 

in auth/email/auth.php

add the following to function user_confirm, about line 136, right before return AUTH_CONFIRM_OK;

    // get libraries
    require_once($CFG->libdir.'/enrollib.php');
    // get plugin
    $plugin = enrol_get_plugin('manual');
    // id of course signups should be in
    $targetcourseid = 5;
    // create instance
    $enrolperson = $DB -> get_record('enrol',array('courseid'=>$targetcourseid,'enrol'=>'manual'));
    // do enrollment
    $plugin->enrol_user($enrolperson,$user->id,$targetcourseid);

you will also need to add $CFG to the globals for user_confirm

i.e.

global $DB,$CFG;