3 require_once($CFG->libdir
.'/formslib.php');
5 class login_signup_form
extends moodleform
{
6 function definition() {
9 $mform =& $this->_form
;
11 $mform->addElement('header', '', get_string('createuserandpass'), '');
14 $mform->addElement('text', 'username', get_string('username'), 'maxlength="100" size="12"');
15 $mform->setType('username', PARAM_NOTAGS
);
16 $mform->addRule('username', get_string('missingusername'), 'required', null, 'server');
18 $mform->addElement('passwordunmask', 'password', get_string('password'), 'maxlength="32" size="12"');
19 $mform->setType('password', PARAM_RAW
);
20 $mform->addRule('password', get_string('missingpassword'), 'required', null, 'server');
22 $mform->addElement('header', '', get_string('supplyinfo'),'');
24 $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="25"');
25 $mform->setType('email', PARAM_NOTAGS
);
26 $mform->addRule('email', get_string('missingemail'), 'required', null, 'server');
28 $mform->addElement('text', 'email2', get_string('emailagain'), 'maxlength="100" size="25"');
29 $mform->setType('email2', PARAM_NOTAGS
);
30 $mform->addRule('email2', get_string('missingemail'), 'required', null, 'server');
32 $nameordercheck->firstname
= 'a';
33 $nameordercheck->lastname
= 'b';
34 if (fullname($nameordercheck) == 'b a' ) { // See MDL-4325
35 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
36 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
38 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
39 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
42 $mform->setType('firstname', PARAM_TEXT
);
43 $mform->addRule('firstname', get_string('missingfirstname'), 'required', null, 'server');
45 $mform->setType('lastname', PARAM_TEXT
);
46 $mform->addRule('lastname', get_string('missinglastname'), 'required', null, 'server');
48 $mform->addElement('text', 'city', get_string('city'), 'maxlength="20" size="20"');
49 $mform->setType('city', PARAM_TEXT
);
50 $mform->addRule('city', get_string('missingcity'), 'required', null, 'server');
52 $country = get_list_of_countries();
53 $default_country[''] = get_string('selectacountry');
54 $country = array_merge($default_country, $country);
55 $mform->addElement('select', 'country', get_string('country'), $country);
56 $mform->addRule('country', get_string('missingcountry'), 'required', null, 'server');
57 $mform->setDefault('country', '');
59 if (!empty($CFG->sitepolicy
)) {
60 $mform->addElement('header', '', get_string('policyagreement'), '');
61 $mform->addElement('static', 'policylink', '', '<a href="'.$CFG->sitepolicy
.'" onclick="this.target=\'_blank\'">'.get_String('policyagreementclick').'</a>');
62 $mform->addElement('checkbox', 'policyagreed', get_string('policyaccept'));
63 $mform->addRule('policyagreed', get_string('policyagree'), 'required', null, 'server');
67 $this->add_action_buttons(true, get_string('createaccount'));
71 function definition_after_data(){
72 $mform =& $this->_form
;
74 $mform->applyFilter('username', 'moodle_strtolower');
75 $mform->applyFilter('username', 'trim');
78 function validation($data) {
82 $authplugin = get_auth_plugin($CFG->registerauth
);
84 if (record_exists('user', 'username', $data['username'], 'mnethostid', $CFG->mnet_localhost_id
)) {
85 $errors['username'] = get_string('usernameexists');
87 if (empty($CFG->extendedusernamechars
)) {
88 $string = eregi_replace("[^(-\.[:alnum:])]", '', $data['username']);
89 if (strcmp($data['username'], $string)) {
90 $errors['username'] = get_string('alphanumerical');
95 //check if user exists in external db
96 //TODO: maybe we should check all enabled plugins instead
97 if ($authplugin->user_exists($data['username'])) {
98 $errors['username'] = get_string('usernameexists');
102 if (! validate_email($data['email'])) {
103 $errors['email'] = get_string('invalidemail');
105 } else if (record_exists('user', 'email', $data['email'])) {
106 $errors['email'] = get_string('emailexists').' <a href="forgot_password.php">'.get_string('newpassword').'?</a>';
108 if (empty($data['email2'])) {
109 $errors['email2'] = get_string('missingemail');
111 } else if ($data['email2'] != $data['email']) {
112 $errors['email2'] = get_string('invalidemail');
114 if (!isset($errors['email'])) {
115 if ($err = email_is_not_allowed($data['email'])) {
116 $errors['email'] = $err;
121 if (!check_password_policy($data['password'], $errmsg)) {
122 $errors['password'] = $errmsg;
125 if (0 == count($errors)){