I would like to change the fields that are required when adding students to the course. My students only need a username, first name, last name, and a password. I don't need a city, country, or email. How can I take these off. I have to update my database each week, and it would be much easier for me if I could just import my database over from the secure server instead of having to insert these meaningless fields. Can somebody please help by telling me how to change the fields so they are option instead of required. Thanks.
In /user/editlib.php, search for $mform->addRule. You'll see it for firstname, lastname, email, city, and country. Comment out the appropriate lines for the fields you don't want to require.
Then, to remove the checks Moodle makes to make sure the email is valid and doesn't already exist, you'll need to comment out some code in /user/editadvanced_form.php. Look for the following code (lines 133-139 on my install) and comment it out:
if (!$user or $user->email !== $usernew->email) {
if (!validate_email($usernew->email)) {
$err['email'] = get_string('invalidemail');
} else if (record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
$err['email'] = get_string('emailexists');
}
}
I'm currently using this on 1.8.2 and have disabled the email, city, and country requirements, and it seems to work just fine.
Thanks,
Matt
Thanks,
Matt
Matt,
Thanks for posting this info.
I'm a novice to php and mysql - however, I can edit the php easily enough as you suggest, but don't know where to get started with MySQL and allowing null fields. I've been trying to connect with MySQLAdmin without any luck - not sure if I'm using the wrong tool or the wrong technique!
If there was a way to hard code a default text value into the php I might find this easier (e.g. so the city is always Birmingham)...
Any advice much appreciated,
Regards,
Niall.
Matt, I want to not just make it a nonrequirement, but I want to remove the city and country field altogether. I am NOT a techy, at all. I do not understand techy talk. I have been trying to accomplish this for a few days, and I am at the point of tears and anger, and it takes a lot to get me there. I was told to comment out code and I was given examples. Nothing changed at all. I finally found out how the hell to get to MyPHPAdmin, and I was told to allow nulls, but there does not seem to be an option of "null", so how do I do this. There is a column that says "Null", but it is static and not dynamic. There is not a damned thing I can do with it. I just want the damned fields removed. Is it really this frickin' hard?!?!? Is anyone able to explain how the hell to do this? Is anyone out there knowledgeable enough to teach this?
This is fairly easy to do but it is a core change. If you are comfortable with that do the following:
You need to change the user/editlib.php file. Find the line that says that the field you are referencing is required and comment it out by placing a # symbol at the beginning of the line. Sorry, I don't have the exact line because in the latest versions of Moodle, they have removed this requirement but it is fairly easy. Just search for city within the code and you will a line or two that contains 'isrequired'. Make a copy of the file first in case you delete out the wrong part (which might cause the page not to load).
Alternatively, you could upgrade to 2.6 where those fields are no longer required!
Thanks.
Thanks,
Matt
I do not use moodle 1.8 so did not realise you could add more fields from within moodle. Here is how i think you can adjust the fields to be required that are available as default.
My example shows how to change the idnumber field to be a requirement. Look at the www.mymoodle.com/user/editlib.php file and follow the example and alter to reflect any other optional field.
Follow this link : http://moodle.org/mod/forum/discuss.php?d=84910&parent=375991
Regards
Steve
Is there any way to disable the 'advanced' setting for optional information in profiles? This contains fields that I would rather my students didn't use, for their own security (e.g. address, phone number). I would like to be able to remove the 'advanced' button completely.
Many thanks.
Lynne
If anyone else has this problem, what I did (which is probably not the best way) was I went into the "user" folder and found the editlib.php page. I then changed the "maxlengths" to zero in the fields I don't want the students to fill in. For example:
$mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="0" size="25"');
$mform->setType('aim', PARAM_CLEAN);
What this does is leave the blank on the form, yet zero characters can be entered. I'm sure there must be a better way to do this, but this is a quick fix.
Prob too late now, but the only way I could see to disable this button was to add this to my CSS:
div.advancedbutton {display:none;}
Hope this helps!
Ciara
Any suggestions or anyone else successful with this?
CHANGE:
function user_not_fully_set_up($user) {
return ($user->username != 'guest' and (empty($user->firstname) or empty($user->lastname) or empty($user->email) or over_bounce_threshold($user)));
}
TO:
function user_not_fully_set_up($user) {
return ($user->username != 'guest' and (empty($user->firstname) or empty($user->lastname) or over_bounce_threshold($user)));
}
Much thanks.
This happened after I edited the files:, (commenting out lines)
"/user/editlib.php and if you want to remove the email requirement, /user/editadvanced_form.php."
to make it so that the e-mail address is not a required field.
I thought that this worked, I imported users, and it no longer stated e-mail as "Required", however, whenever a student logged in, it brought them to their profile. If they tried to go anywhere else using the breadcrumb trail, it just kept returning to the profile page.
So, I "un-commented" my original changes, and saved the files, and since then I see the error. I can't imagine how I should have affected the database, but in hindsight I should have just given them dummy e-mails...
Any ideas?
Any help is much appreciated.
Associated problem which has been bugging me for well over a year - does anyone know how to ensure that when a user joins themselves onto the system but when they are already linked to the LDAP/AD record - persistently the Forename field in the profile page does not offer a text box hence the person can never move beyond this until the administrator has completed their forename for them.
any help would really be appreciated
thanks
Neil
Can someone please post how to just force in a default email. The directions given above do not get me past the ability to sign in, it continues to give the valid email error. I can't seem to track down where I can just force in a random email because I don't care what goes in there I just want it to allow students in.
I use moodle 1.9.2+
Yes this would be very helpful, I'm also running 1.9.2+ and I was able to stop the City and State but not the email.
Thank you,
John
I've comented the "$mform->addRule" lines for city and country, and modified the database... no changes at all, even comenting the "$mform->setType" and "$mform->addElement" lines. The fields still appearing in Moodle 1.9.2+
Any Idea ???
Thanks !
user/editlib.php
~ Line 198: $mform->addRule('city', $strrequired, 'required', null, 'client');
~ Line 204: $mform->addRule('country', $strrequired, 'required', null, 'client');
This is for 1.9.2, but may be similar for your versions.
Are you using email-based self authentication and your users sign up by clicking "create new account" on the login page?
If this is where you want to remove the requirement for filling in the email and city/country fields, then you need to apply similar edits as above to more files. As you can see from the address bar in your browser, this page is actually generated from /login/signup.php, which calls signup_form.php to actually generate the form.
So inside signup_form.php is where you find the familiar "$mform->addRule(... 'required')" lines that we want to comment out. So, find the email, email2, city and/or country lines and comment them out.
Further down in this file are the email validation checks, which you will also need to disable if you want to remove the email requirements.
Look for the line "if (! validate_email($data['email'])) {". You can just comment out the line after this ("$errors['email']...") to completely disable email validation for the first email field. I went one step further and changed the if statement to read "if (! empty($data['email']) && ! validate_email($data['email'])) {", which will allow the user to either a) leave the email blank or b) enter a proper email address, but will not allow them to enter junk (eg. "adsafg") into the field.
We also need to remove the blank check on the email2 field, to do this but still require that email2 == email (in case the user does enter an email address) go down a few lines and comment out the first part of the if statement. It should look something like this:
/* if (empty($data['email2'])) {
$errors['email2'] = get_string('missingemail');
} else */ if ($data['email2'] != $data['email'])) {
Everything between the /* and the */ is commented a comment in this case.
This does not however prevent the site from trying to email the new user with a confirmation email. I disabled all emails by adding $CFG->noemailever = true; to my moodle.cfg as that was what worked for me.
If you are making these kind of edits, you may find it easier with a more featured text editor. Notepad++ has a "find in files" feature which searches for a text string inside all files in a directory - this makes finding where functions are defined or called trivial.
I'm in the same boat and need to remove some required fields. I'm on 1.9.7. Have you found any answers?
thanks.
Rayanne
Using 1.98 I have finally figured this out. Thanx mostly to th ports above this.
In moodle->user->editlib find the rule statements for each field you do not want to be required. This is the e-mail one:
//$mform->addRule('email', $strrequired, 'required', null, 'client');
simpley comment them out. This will make sure that the form willnot require the field to have data. This is all you would have to do for country/city.
If you want moodle to work without requireing e-mails then there is more to it. This is becasue moodle checks to see if the e-mails are e-mails, and that they are unique in the database when the user is craeted, but also when you login the system checks to see if the e-mail, user name, Fname ad Lname are no empty.
In the file moodle->user->editadvanced_form.php is where the initial validation checks occur. You need to find the
function validation($usernew, $files) {
and then comment out the line like i did below.
if (!$user or $user->email !== stripslashes($usernew->email)) {
if (!validate_email(stripslashes($usernew->email))) {
//$err['email'] = get_string('invalidemail');
} else if (record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
//$err['email'] = get_string('emailexists');
}
}
I'm new to php but I'm pretty sure the 2nd if checks to see if the e-mail is blank and the else if checks to see if unique. I wanted to be able to have blanks so a commented out both.
The problem at this point is when a user logs in Moodle checks to see if the user name, first name, e-mail, etc are not blank. If they are blank they will force them to enter in this info. So in moodle->lib->moodlelib.php, find the function
function user_not_fully_set_up($user) {
return ($user->username != 'guest' and (empty($user->firstname) or empty($user->lastname) or empty($user->email) or over_bounce_threshold($user)));
}
not just delete the:
or empty($user->email)
If you are still having problems, check moodle->login->signup_form in the
function validation($data, $files) {
if (! validate_email($data['email'])) {
$errors['email'] = get_string('invalidemail');
} else if (record_exists('user', 'email', $data['email'])) {
$errors['email'] = get_string('emailexists').' <a href="forgot_password.php">'.get_string('newpassword').'?</a>';
}
if (empty($data['email2'])) {
$errors['email2'] = get_string('missingemail');
} else if ($data['email2'] != $data['email']) {
$errors['email2'] = get_string('invalidemail');
}
if (!isset($errors['email'])) {
if ($err = email_is_not_allowed($data['email'])) {
$errors['email'] = $err;
}
}
These errors may be causing trouble, and if they are comment them out.
I did not have any problems with the database not accepting nulls.
If you have any questions just send me a message directly.
I found this all out by using the following steps:
1. I found the error message in moodle->lang->en_utf8->moodle.php - the "invalid email text"
This is where the get_string command get's it's text from. I fond this line:
$string['invalidemail'] = 'Invalid email address';
I then knew that any function calling get_string("'invalidemail'") would cause the error message.
2. I used a program to search through all the code and find get_string("'invalidemail'"). I found it in several places and commented them one at a time to make sure I knew which one was causing the error when I was creating a user.
3. I then tested the system out and found a new error when i tried to login, I followed steps 1 and 2 almost exactly. When i found the error I decided to search for teh function that was failing (function user_not_fully_set_up) and decided just to alter it instead of simply commenting out the error.
In moodle 1.9.9 I found you must also comment out the lines in user/edit_form.php:
// validate email
if (!isset($usernew->email)) {
// mail not confirmed yet
} else if (!validate_email(stripslashes($usernew->email))) {
//$errors['email'] = get_string('invalidemail');
} else if ((stripslashes($usernew->email) !== $user->email) and record_exists('user', 'email', $usernew->email, 'mnethostid', $CFG->mnet_localhost_id)) {
//$errors['email'] = get_string('emailexists');
}
Thanks Mark Pavlis
Remove City requirement worked in 1.9.13
Thanks Marks It's really working for me....
This forum post has been removed
Mark,
Great stuff! Worked perfectly for removing the email requirement from the add user page.
Does anyone know how to remove the email requirement from the user upload page? I would love to be able to upload an entire class of students with a csv file and have the email be left blank.
Any ideas?
Thanks!
I would like to do this for Moodle 2.2. I am running an older version and had it working properly but am starting over with a completely new server installation and new installation of Moodle on the new server. I haven't attempted any of these since Moodle has changed so much with the versions above 2.0.
Please advise.
Hi Katie,
Did you ever get this working in 2.2? I am having a similar problem with wanting default settings changed on the sign up form.
Mark
You'll need to edit /path/to/moodle/login/signup_form.php. Comment out lines 78-97 to remove both country and city.
This does NOT however fix the problem of when you try to edit user settings demanding that they be set. I'll have to keep digging.
The proper place is to edit user/editlib.php and comment out line 221 and 229.
//$mform->addRule('city', $strrequired, 'required', null, 'client'); //$mform->addRule('country', $strrequired, 'required', null, 'client')
Tracker ticket: http://tracker.moodle.org/browse/MDL-28558
This seems to have worked for us, thank you.
I went through the suggestions as far as wanting to not require the email field be used. Since doing that, if a user (manually created) logs in, they get taken straight to "Edit Profile". Every link - courses, My home, etc - they all just redirect back to "Edit Profile". Not sure if I missed something with these suggestions, or if something's changed in my version (2.4.1).
Anyone have any ideas why this might be happening?
Go into lib/moodlelib.php and search for
function user_not_fully_set_up($user) {
if (isguestuser($user)) {
return false;
}
return (empty($user->firstname) or empty($user->lastname) or empty($user->email) or over_bounce_threshold($user));
}
and delete the part: "or empty($user->email)"
so your return string looks like:
return (empty($user->firstname) or empty($user->lastname) or over_bounce_threshold($user));
Hope that helps.
I'm using Moodle 2.5. I got this to work by searching for the fields I did not want to be required then removing the word 'required' from the addRule line like so:
in login/signup_form.php
change from this:
$mform->addRule('country', get_string('missingcountry'), 'required', null, 'server');
to this:
$mform->addRule('country', get_string('missingcountry'), '', null, 'server');
Note I still left the single quote marks, just removed the word required from within them.
I did the same thing in user/editlib.php for the same fields although not sure if it needs to be done in both places. Worked for me, the fields for city and country still show up on the form but are not mandatory.
This forum post has been removed
Hi Joni Seth,
A question though.
I got 2.3.9 and to change the Id & Department field to be mandatory for new students. Any suggestions or I need to have a new forum post?
Good afternoon,
I was wondering if there is new functionality in moodle 2.6.1 (which I currently have) which would allow me to completely remove the sign up fields
Firstname
Lastname
We would like to collect just
Username, password, email, country, postcode etc
The reason for this is that we would like to give our registrants some anonymity (even though we are collecting email addresses which may have their name in it - that is fine)
I've already made 'City/Town' ....Not required (and I could do this with first and last names but it would be even better if I could hide them from the sign up field.
Thanks in advance