I am trying out your directions in order to add a zip code field to the user data, but I'm running into trouble because the data is not being inserted into the
database. Here's what I've done, step-by-step:
1) I created the database field zipcode in the mdl_user table:
Field Type Null Default
zipcode varchar(12) Yes NULL
I wanted to leave room for the zip + 4 in US postal codes which includes a dash, so I made it a 12 character varchar.
2) I put the following in user/edit.html
<tr valign=top>
<td align=right><p><?php print_string("zipcode")?>:</td>
<td><input type="text" name="zipcode" size="12" maxlength="12"
value="<?php p($user->zipcode) ?>">
<?php if (isset($err["zipcode"])) formerr($err["zipcode"]); ?>
</td>
</tr>
3) And the following in user/edit.php :
if (empty($usernew->zipcode))
$err["zip"] = get_string("missingzipcode");
This worked, making zipcode a required field with an error message. I eventually commented it out because it's not necessary to require it.
4) And the following in lang/en/moodle.php:
$string['zipcode'] = 'Postal Code';
$string['missingzipcode'] = 'Postal Code is a required field.';
5) I put the following in user/view.php:
if ($user->zipcode) {
print_row(get_string("zipcode").":", "$user->zipcode");
}
I didn't initially alter user/view.php because I won't be displaying the data there, but then I decided to try to be consistent with what you've done until I get this working.
6) I tested that the variable was being set by echoing it back on the page
and not filling out the required City field. It was displayed as I expected.
<? echo("Zip: " . $zipcode); ?>
It appears that everything is in order except data is not being inserted into the database.