Jan 9, 2009

Fixing the State/Province problem in the Moodle signup process

Moodle has the known problem of not asking for state/province information from the user upon signup. Working with people from the U.S., this has become a must have. Thus, I've made the following quick fix for this issue. Here are the steps:

  1. Alter your user table (i.e. mdl_user) to include a province field of type text.

  2. Add the following 2 lines of PHP in your lang/en_utf8/moodle.php:
    $string['missingprovince'] = 'Missing state/province';
    $string['province'] = 'State/Province';

  3. Add the following 3 lines of PHP in your login/signup_form.php:
    $mform->addElement('text', 'province', get_string('province'), 'maxlength="20" size="20"');
    $mform->setType('province', PARAM_TEXT);
    $mform->addRule('province', get_string('missingprovince'), 'required', null, 'server');

  4. Add the following 3 lines of PHP in your user/editlib.php (line 200):
    $mform->addElement('text', 'province', get_string('province'), 'maxlength="20" size="21"');
    $mform->setType('province', PARAM_MULTILANG);
    $mform->addRule('province', $strrequired, 'required', null, 'client');

Additionally, if you like the bulk download feature for user information, add the following line to your $fields array in admin/user/user_bulk_download.php (line 32):
'province'  => 'province'
Enjoy! :)

No comments: