MDL-9004 - Breadcrumb trail is wrong when editing a quiz question. Merged from MOODLE...
[moodle.git] / login / signup_form.php
CommitLineData
296c2a79 1<?php // $Id$
2
3require_once($CFG->libdir.'/formslib.php');
4
dd0feda5 5class login_signup_form extends moodleform {
e8a34ad4 6 function definition() {
7 global $USER, $CFG;
8
dd0feda5 9 $mform =& $this->_form;
e8a34ad4 10
296c2a79 11 $mform->addElement('header', '', get_string('createuserandpass'), '');
e8a34ad4 12
13
296c2a79 14 $mform->addElement('text', 'username', get_string('username'), 'size="12"');
e8a34ad4 15 $mform->setType('username', PARAM_NOTAGS);
296c2a79 16 $mform->addRule('username', get_string('missingusername'), 'required', null, 'client');
e8a34ad4 17
296c2a79 18 $mform->addElement('password', 'password', get_string('password'), 'size="12"');
e8a34ad4 19 $mform->setType('password', PARAM_RAW);
296c2a79 20 $mform->addRule('password', get_string('missingpassword'), 'required', null, 'client');
e8a34ad4 21
22 $mform->addElement('header', '', get_string('supplyinfo'),'');
23
296c2a79 24 $mform->addElement('text', 'email', get_string('email'), 'size="25"');
e8a34ad4 25 $mform->setType('email', PARAM_NOTAGS);
296c2a79 26 $mform->addRule('email', get_string('missingemail'), 'required', null, 'client');
e8a34ad4 27
296c2a79 28 $mform->addElement('text', 'email2', get_string('emailagain'), 'size="25"');
e8a34ad4 29 $mform->setType('email2', PARAM_NOTAGS);
296c2a79 30 $mform->addRule('email2', get_string('missingemail'), 'required', null, 'client');
e8a34ad4 31
296c2a79 32 $mform->addElement('text', 'firstname', get_string('firstname'), 'size="25"');
e8a34ad4 33 $mform->setType('firstname', PARAM_TEXT);
296c2a79 34 $mform->addRule('firstname', get_string('missingfirstname'), 'required', null, 'client');
e8a34ad4 35
296c2a79 36 $mform->addElement('text', 'lastname', get_string('lastname'), 'size="25"');
e8a34ad4 37 $mform->setType('lastname', PARAM_TEXT);
296c2a79 38 $mform->addRule('lastname', get_string('missinglastname'), 'required', null, 'client');
e8a34ad4 39
6e394912 40 $mform->addElement('text', 'city', get_string('city'), 'size="20"');
e8a34ad4 41 $mform->setType('city', PARAM_TEXT);
296c2a79 42 $mform->addRule('city', get_string('missingcity'), 'required', null, 'client');
e8a34ad4 43
296c2a79 44 $country = get_list_of_countries();
45 $default_country[''] = get_string('selectacountry');
46 $country = array_merge($default_country, $country);
47 $mform->addElement('select', 'country', get_string('country'), $country);
48 $mform->addRule('country', get_string('missingcountry'), 'required', null, 'client');
49 $mform->setDefault('country', '');
e8a34ad4 50
5d2b6c1c 51 // buttons
b6d15dde 52 $this->add_action_buttons(true, get_string('createaccount'));
e8a34ad4 53
e8a34ad4 54 }
296c2a79 55
e8a34ad4 56 function definition_after_data(){
296c2a79 57 $mform =& $this->_form;
58
e8a34ad4 59 $mform->applyFilter('username', 'moodle_strtolower');
60 $mform->applyFilter('username', 'trim');
61 }
62
63 function validation($data) {
64 global $CFG;
296c2a79 65 $errors = array();
e8a34ad4 66
3fe6b721 67 $authplugin = get_auth_plugin($CFG->registerauth);
e8a34ad4 68
5f88a475 69 if (record_exists('user', 'username', $data['username'], 'mnethostid', $CFG->mnet_localhost_id)) {
296c2a79 70 $errors['username'] = get_string('usernameexists');
e8a34ad4 71 } else {
72 if (empty($CFG->extendedusernamechars)) {
296c2a79 73 $string = eregi_replace("[^(-\.[:alnum:])]", '', $data['username']);
e8a34ad4 74 if (strcmp($data['username'], $string)) {
296c2a79 75 $errors['username'] = get_string('alphanumerical');
e8a34ad4 76 }
77 }
78 }
3fe6b721 79 if (method_exists($authplugin, 'user_exists')){
af9c5226 80 if ($authplugin->user_exists($user->username)) {
296c2a79 81 $errors['username'] = get_string('usernameexists');
e8a34ad4 82 }
83 }
84
85
86 if (! validate_email($data['email'])) {
296c2a79 87 $errors['email'] = get_string('invalidemail');
e8a34ad4 88
296c2a79 89 } else if (record_exists('user', 'email', $data['email'])) {
90 $errors['email'] = get_string('emailexists').' <a href="forgot_password.php">'.get_string('newpassword').'?</a>';
e8a34ad4 91 }
92 if (empty($data['email2'])) {
296c2a79 93 $errors['email2'] = get_string('missingemail');
e8a34ad4 94
95 } else if ($data['email2'] != $data['email']) {
296c2a79 96 $errors['email2'] = get_string('invalidemail');
e8a34ad4 97 }
98 if (!isset($errors['email'])) {
99 if ($err = email_is_not_allowed($data['email'])) {
100 $errors['email'] = $err;
101 }
102
103 }
104
105
106 if (0 == count($errors)){
107 return true;
108 } else {
109 return $errors;
110 }
111
112
113 }
114}
115
116?>