MDL-8857
[moodle-linuxchix.git] / login / signup_form.php
blob7a7081ab3831421e5b5ee8b5f38e97d81ff8582d
1 <?php // $Id$
3 require_once($CFG->libdir.'/formslib.php');
5 class login_signup_form extends moodleform {
6 function definition() {
7 global $USER, $CFG;
9 $mform =& $this->_form;
11 $mform->addElement('header', '', get_string('createuserandpass'), '');
14 $mform->addElement('text', 'username', get_string('username'), 'size="12"');
15 $mform->setType('username', PARAM_NOTAGS);
16 $mform->addRule('username', get_string('missingusername'), 'required', null, 'client');
18 $mform->addElement('password', 'password', get_string('password'), 'size="12"');
19 $mform->setType('password', PARAM_RAW);
20 $mform->addRule('password', get_string('missingpassword'), 'required', null, 'client');
22 $mform->addElement('header', '', get_string('supplyinfo'),'');
24 $mform->addElement('text', 'email', get_string('email'), 'size="25"');
25 $mform->setType('email', PARAM_NOTAGS);
26 $mform->addRule('email', get_string('missingemail'), 'required', null, 'client');
28 $mform->addElement('text', 'email2', get_string('emailagain'), 'size="25"');
29 $mform->setType('email2', PARAM_NOTAGS);
30 $mform->addRule('email2', get_string('missingemail'), 'required', null, 'client');
32 $mform->addElement('text', 'firstname', get_string('firstname'), 'size="25"');
33 $mform->setType('firstname', PARAM_TEXT);
34 $mform->addRule('firstname', get_string('missingfirstname'), 'required', null, 'client');
36 $mform->addElement('text', 'lastname', get_string('lastname'), 'size="25"');
37 $mform->setType('lastname', PARAM_TEXT);
38 $mform->addRule('lastname', get_string('missinglastname'), 'required', null, 'client');
40 $mform->addElement('text', 'city', get_string('city'), 'size="20"');
41 $mform->setType('city', PARAM_TEXT);
42 $mform->addRule('city', get_string('missingcity'), 'required', null, 'client');
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', '');
51 // buttons
52 $this->add_action_buttons(true, get_string('createaccount'));
56 function definition_after_data(){
57 $mform =& $this->_form;
59 $mform->applyFilter('username', 'moodle_strtolower');
60 $mform->applyFilter('username', 'trim');
63 function validation($data) {
64 global $CFG;
65 $errors = array();
67 $authplugin = get_auth_plugin($CFG->registerauth);
69 if (record_exists('user', 'username', $data['username'], 'mnethostid', $CFG->mnet_localhost_id)) {
70 $errors['username'] = get_string('usernameexists');
71 } else {
72 if (empty($CFG->extendedusernamechars)) {
73 $string = eregi_replace("[^(-\.[:alnum:])]", '', $data['username']);
74 if (strcmp($data['username'], $string)) {
75 $errors['username'] = get_string('alphanumerical');
79 if (method_exists($authplugin, 'user_exists')){
80 if ($authplugin->user_exists($user->username)) {
81 $errors['username'] = get_string('usernameexists');
86 if (! validate_email($data['email'])) {
87 $errors['email'] = get_string('invalidemail');
89 } else if (record_exists('user', 'email', $data['email'])) {
90 $errors['email'] = get_string('emailexists').' <a href="forgot_password.php">'.get_string('newpassword').'?</a>';
92 if (empty($data['email2'])) {
93 $errors['email2'] = get_string('missingemail');
95 } else if ($data['email2'] != $data['email']) {
96 $errors['email2'] = get_string('invalidemail');
98 if (!isset($errors['email'])) {
99 if ($err = email_is_not_allowed($data['email'])) {
100 $errors['email'] = $err;
106 if (0 == count($errors)){
107 return true;
108 } else {
109 return $errors;