Prepopulate registration form with URL variables

Prepopulate registration form with URL variables

by Alec Myers -
Number of replies: 3

Hi


I'm new to Moodle. 


I'd like to send out emails to customers to register on my moodle site each with a personalized link which prefills some fields on the registration page (including a custom profile field).


I believe it would be appropriate to patch signup_form.php with relevant calls 

 $mform->set_default("myelementname",optional_param(...));

Am I on the the right track? Is this the best way to achieve this? Would this patch be welcomed?


Thanks



Average of ratings: -
In reply to Alec Myers

Re: Prepopulate registration form with URL variables

by Darko Miletić -

In general terms that would be a way to implement what you want. I doubt such a patch would be accepted into core.

What I would suggest to you is to create a fork of auth_email plugin and add the functionality you need. That way you keep everything as it should be and maintain complete control over code.


In reply to Darko Miletić

Re: Prepopulate registration form with URL variables

by Alec Myers -

Thanks I have implemented it and it works.

But signup_form.php isn't part of auth_email so I don't see how forking that module would help.

Also for profile fields, it needs two extra lines in  user/profile/lib.php

When you say it wouldn't be accepted into core, what's the criteria for this? Do you speak with authority? Are you telling me not to waste my time suggesting it?


In reply to Alec Myers

Re: Prepopulate registration form with URL variables

by Darko Miletić -

You can completely override the form in your forked plugin whatever it may be.

auth_plugin_base class implements public method signup_form that returns the form object. In order to have your own version just override the method in your fork and provide your own class.

This is the original code:

    function signup_form() {
        global $CFG;

        require_once($CFG->dirroot.'/login/signup_form.php');
        return new login_signup_form(null, null, 'post', '', array('autocomplete'=>'on'));
    }

It is obvious that there is no need for core modification, just new authentication plugin.