changing required fields for new students

changing required fields for new students

Michael Carroll發表於
Number of replies: 50

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.

評比平均分數:Useful (2)
In reply to Michael Carroll

Re: changing required fields for new students

Kevin Bennett發表於
If anyone can point the way to achieving this, I too would be very grateful. Having the City and Country as required fields is inconvenient for me.
In reply to Michael Carroll

Re: changing required fields for new students

Matt Campbell發表於
Okay, in 1.8.x there are a couple of files you'll have to update to do this - /user/editlib.php and if you want to remove the email requirement, /user/editadvanced_form.php.

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
評比平均分數:Useful (3)
In reply to Matt Campbell

Re: changing required fields for new students

Matt Campbell發表於
Oh, and I forgot about this - check mdl_user and allow nulls in any of those fields that you need, I think the default setting on those is to require a value. Be sure to backup your database before making this sort of change, so you can recover if needed.

Thanks,
Matt
評比平均分數:Useful (1)
In reply to Matt Campbell

Re: changing required fields for new students

Niall Poole發表於

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.

In reply to Matt Campbell

Re: changing required fields for new students

Wendi Daniels發表於

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?

In reply to Wendi Daniels

Re: changing required fields for new students

Emma Richardson發表於
Documentation writers的相片 Particularly helpful Moodlers的相片 Plugin developers的相片

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!

評比平均分數:Useful (1)
In reply to Matt Campbell

Re: changing required fields for new students

Daniel Israel發表於
Cool. Can a similar method be used to add required fields? I would like to require an address, and ideally a zip code. The former would mean not only making that field required, but adding that field to the form altogether, it currently only appears when users edit their profile. The latter is not in the profile at all, so perhaps is beyond a simple hack. If so, is there a way to add text so I can label the address box "Street Address, City, State, Zip"?

Thanks.
In reply to Daniel Israel

Re: changing required fields for new students

Matt Campbell發表於
If you're using 1.8, take a look at User->Accounts->User profile fields. You can set additional fields here and have them required, locked, etc. You may also want to take a look at MDL-10504, which is a tracker issue that's been filed to be able to sort these additional fields and place them in with the rest of the user's profile, instead of all at the bottom.

Thanks,
Matt
In reply to Matt Campbell

Re: changing required fields for new students

Steve Bilton發表於
I have just replied to someone regarding required fields.
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
In reply to Matt Campbell

Re: changing required fields for new students

Lynne McCulloch發表於

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

In reply to Lynne McCulloch

Re: changing required fields for new students

Linda B發表於
Did anyone figure out how to remove/disable the advanced optional settings in the user profiles?  I too think it is a security issue for school aged children using Moodle.  Any ideas?  Thank you!
In reply to Linda B

Re: changing required fields for new students

Linda B發表於

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.

In reply to Lynne McCulloch

Re: changing required fields for new students

Ciara Rogers發表於
Hi Lynne,

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
In reply to Matt Campbell

Re: changing required fields for new students

Jason Raby發表於
I'm using 1.9.1+ and this doesn't seem to be working. It removes the requirement, but still sees that a blank email field is not a valid email address. I using MySQL Administrator and unchecked "Not Null" for the email field as well.
In reply to Jason Raby

Re: changing required fields for new students

KT Fav發表於
Was this ever resolved for version 1.9+? I am trying to do the same thing with no success. I have altered the database to allow null. I have searched and commented out every item in several different files that refer to validating the email address. However, it won't move on. It does not give the error, but will not pass the profile page.

Any suggestions or anyone else successful with this?
In reply to KT Fav

Re: changing required fields for new students

Chris Bowers發表於
It is giving an error, you just can't see it since you removed the e-mail field. Basically it is just saying "Required Invalid Email Address." I have been completely unsuccessful getting this to work on 1.9.2
In reply to Jason Raby

Re: changing required fields for new students

Tyler Kowalchuk發表於
The reason it does this, is it checks to see if the user is setup correctly every time a student tries to enter a course. To disable this, remove 'or empty($user->email)' from the function "user_not_fully_set_up" in the file "lib/moodlelib.php"

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)));
}
In reply to Matt Campbell

Re: changing required fields for new students

Kimberly Yuretich發表於
I am getting the Error "database connection failed".
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.
In reply to Kimberly Yuretich

Re: changing required fields for new students

Neil Spurgeon發表於

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

In reply to Neil Spurgeon

Re: changing required fields for new students

Tyler Kowalchuk發表於
Where you set up LDAP, (users->auth->ldap server) towards the bottom in the field mapping section, there is a setting next to each field to lock it so the user can't modify the field contents. Either change this to "unlocked" or "unlocked if empty".
In reply to Michael Carroll

Re: changing required fields for new students

Justin Hedrington發表於

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+

In reply to Justin Hedrington

Re: changing required fields for new students

John Joseph發表於

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

In reply to John Joseph

Re: changing required fields for new students

Matthew Edmondson發表於
+1 I am having similar issues.


In reply to Matthew Edmondson

Re: changing required fields for new students

Miquel Ràmia Jesús發表於
+1 , but I couldn't disable the "required" property of city and county from my register form. Furthermore, they are still shown as required and alerted when they are left empty.

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 !
In reply to Miquel Ràmia Jesús

Re: changing required fields for new students

j h發表於
I disabled the requirement for city and country by commenting out these lines in Moodle 1.9.3. I did not have to change the database.

user/editlib.php
~ Line 198: $mform->addRule('city', $strrequired, 'required', null, 'client');
~ Line 204: $mform->addRule('country', $strrequired, 'required', null, 'client');


評比平均分數:Useful (1)
In reply to j h

Re: changing required fields for new students

w dampier發表於
Commented out those lines in user/editlib.php. Had no impact on user enrolment form: still shows city.country as required fields, still will not propcess enrollment without them.

In reply to w dampier

Re: changing required fields for new students

klebe stift發表於

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.

評比平均分數:Useful (1)
In reply to Michael Carroll

Re: changing required fields for new students

Michael O'Shea發表於
This is an old post, but I'm having these problems. I have tried just about everything that has been posted to help remove the City, Email and Country required fields, but I have had no luck. I am using version 1.9.8 and continue to get no results. If anyone can please help me out that would be excellent!
In reply to Michael O'Shea

Re: changing required fields for new students

Rayanne Rogers發表於
Michael,
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
In reply to Rayanne Rogers

Re: changing required fields for new students

Mark Pavlis發表於

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.

評比平均分數:Useful (4)
In reply to Mark Pavlis

Re: changing required fields for new students

Aaron Johnson發表於

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');
}

In reply to Mark Pavlis

這一討論區的貼文已經被移除

這一討論區的貼文已經被移除且無法再被存取
In reply to Mark Pavlis

Re: changing required fields for new students

Dan Caldwell發表於

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!

In reply to Michael Carroll

Re: changing required fields for new students

KT Fav發表於

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.

In reply to KT Fav

Re: changing required fields for new students

Mark B發表於

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

In reply to Mark B

Re: changing required fields for new students

Eric Ellis發表於

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. 

In reply to Eric Ellis

Re: changing required fields for new students

Rex Lorenzo發表於

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

評比平均分數:Useful (1)
In reply to Rex Lorenzo

Re: changing required fields for new students

Jamie Milliken發表於

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?

In reply to Jamie Milliken

Re: changing required fields for new students

Michael E發表於

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.

 

In reply to Eric Ellis

Re: changing required fields for new students

Marty Miller-Crispe發表於

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.

 

評比平均分數:Useful (1)
In reply to Mark B

這一討論區的貼文已經被移除

這一討論區的貼文已經被移除且無法再被存取
In reply to Deleted user

Re: changing required fields for new students

Simon Maina發表於

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?

 

 

In reply to Simon Maina

Re: changing required fields for new students

David P發表於

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