quiz editing: MDL-20263 When adding a new question directly to the quiz, highlight...
[moodle.git] / login / signup_form.php
blob37eaf9c15f133d247a93f952fc33781cbfa26ac7
1 <?php
3 require_once($CFG->libdir.'/formslib.php');
4 require_once($CFG->dirroot.'/user/profile/lib.php');
6 class login_signup_form extends moodleform {
7 function definition() {
8 global $USER, $CFG;
10 $mform =& $this->_form;
12 $mform->addElement('header', '', get_string('createuserandpass'), '');
15 $mform->addElement('text', 'username', get_string('username'), 'maxlength="100" size="12"');
16 $mform->setType('username', PARAM_NOTAGS);
17 $mform->addRule('username', get_string('missingusername'), 'required', null, 'server');
19 if (!empty($CFG->passwordpolicy)){
20 $mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());
22 $mform->addElement('passwordunmask', 'password', get_string('password'), 'maxlength="32" size="12"');
23 $mform->setType('password', PARAM_RAW);
24 $mform->addRule('password', get_string('missingpassword'), 'required', null, 'server');
26 $mform->addElement('header', '', get_string('supplyinfo'),'');
28 $mform->addElement('text', 'email', get_string('email'), 'maxlength="100" size="25"');
29 $mform->setType('email', PARAM_NOTAGS);
30 $mform->addRule('email', get_string('missingemail'), 'required', null, 'server');
32 $mform->addElement('text', 'email2', get_string('emailagain'), 'maxlength="100" size="25"');
33 $mform->setType('email2', PARAM_NOTAGS);
34 $mform->addRule('email2', get_string('missingemail'), 'required', null, 'server');
36 $nameordercheck = new object();
37 $nameordercheck->firstname = 'a';
38 $nameordercheck->lastname = 'b';
39 if (fullname($nameordercheck) == 'b a' ) { // See MDL-4325
40 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
41 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
42 } else {
43 $mform->addElement('text', 'firstname', get_string('firstname'), 'maxlength="100" size="30"');
44 $mform->addElement('text', 'lastname', get_string('lastname'), 'maxlength="100" size="30"');
47 $mform->setType('firstname', PARAM_TEXT);
48 $mform->addRule('firstname', get_string('missingfirstname'), 'required', null, 'server');
50 $mform->setType('lastname', PARAM_TEXT);
51 $mform->addRule('lastname', get_string('missinglastname'), 'required', null, 'server');
53 $mform->addElement('text', 'city', get_string('city'), 'maxlength="20" size="20"');
54 $mform->setType('city', PARAM_TEXT);
55 $mform->addRule('city', get_string('missingcity'), 'required', null, 'server');
57 $country = get_string_manager()->get_list_of_countries();
58 $default_country[''] = get_string('selectacountry');
59 $country = array_merge($default_country, $country);
60 $mform->addElement('select', 'country', get_string('country'), $country);
61 $mform->addRule('country', get_string('missingcountry'), 'required', null, 'server');
63 if( !empty($CFG->country) ){
64 $mform->setDefault('country', $CFG->country);
65 }else{
66 $mform->setDefault('country', '');
69 if (signup_captcha_enabled()) {
70 $mform->addElement('recaptcha', 'recaptcha_element', get_string('recaptcha', 'auth'), array('https' => $CFG->loginhttps));
71 $mform->setHelpButton('recaptcha_element', array('recaptcha', get_string('recaptcha', 'auth')));
74 profile_signup_fields($mform);
76 if (!empty($CFG->sitepolicy)) {
77 $mform->addElement('header', '', get_string('policyagreement'), '');
78 $mform->addElement('static', 'policylink', '', '<a href="'.$CFG->sitepolicy.'" onclick="this.target=\'_blank\'">'.get_String('policyagreementclick').'</a>');
79 $mform->addElement('checkbox', 'policyagreed', get_string('policyaccept'));
80 $mform->addRule('policyagreed', get_string('policyagree'), 'required', null, 'server');
83 // buttons
84 $this->add_action_buttons(true, get_string('createaccount'));
88 function definition_after_data(){
89 $mform =& $this->_form;
90 $mform->applyFilter('username', 'trim');
93 function validation($data, $files) {
94 global $CFG, $DB;
95 $errors = parent::validation($data, $files);
97 $authplugin = get_auth_plugin($CFG->registerauth);
99 if ($DB->record_exists('user', array('username'=>$data['username'], 'mnethostid'=>$CFG->mnet_localhost_id))) {
100 $errors['username'] = get_string('usernameexists');
101 } else {
102 //check allowed characters
103 if ($data['username'] !== moodle_strtolower($data['username'])) {
104 $errors['username'] = get_string('usernamelowercase');
105 } else {
106 $string = clean_param($data['username'], PARAM_USERNAME);
107 if (strcmp($data['username'], $string)) {
108 $errors['username'] = get_string('invalidusername');
114 //check if user exists in external db
115 //TODO: maybe we should check all enabled plugins instead
116 if ($authplugin->user_exists($data['username'])) {
117 $errors['username'] = get_string('usernameexists');
121 if (! validate_email($data['email'])) {
122 $errors['email'] = get_string('invalidemail');
124 } else if ($DB->record_exists('user', array('email'=>$data['email']))) {
125 $errors['email'] = get_string('emailexists').' <a href="forgot_password.php">'.get_string('newpassword').'?</a>';
127 if (empty($data['email2'])) {
128 $errors['email2'] = get_string('missingemail');
130 } else if ($data['email2'] != $data['email']) {
131 $errors['email2'] = get_string('invalidemail');
133 if (!isset($errors['email'])) {
134 if ($err = email_is_not_allowed($data['email'])) {
135 $errors['email'] = $err;
140 $errmsg = '';
141 if (!check_password_policy($data['password'], $errmsg)) {
142 $errors['password'] = $errmsg;
145 if (signup_captcha_enabled()) {
146 $recaptcha_element = $this->_form->getElement('recaptcha_element');
147 if (!empty($this->_form->_submitValues['recaptcha_challenge_field'])) {
148 $challenge_field = $this->_form->_submitValues['recaptcha_challenge_field'];
149 $response_field = $this->_form->_submitValues['recaptcha_response_field'];
150 if (true !== ($result = $recaptcha_element->verify($challenge_field, $response_field))) {
151 $errors['recaptcha'] = $result;
153 } else {
154 $errors['recaptcha'] = get_string('missingrecaptchachallengefield');
158 return $errors;