Adding Custom Field to Web User in MODx Evolution

Right, this is a dirty fix…

As far as I can see there isn't a plugin that exists (or an easy way to create one) which will allow custom web user fields into the CMS. Based on this, this how how it can be done.

Firstly, reuse any fields that are there, but you don't need by editing the labels in /manager/includes/lang/english.inc.php (or your own language). This will reduce the amount of hacking you need to to.

Now if that's not enough, you need to play with the core code. This needs to be done in a couple of places:

/manager/actions/mutate_web_user.dynamic.php
This is the html form which you see as an administrator. Add new rows and fields in here with unique names, e.g.

<tr>
<td valign="top"><?php echo $_lang['user_address']; ?>:</td>
<td>&nbsp;</td>
<td><textarea type="text" name="address"  rows="5" onchange="documentDirty=true;"><?php echo htmlspecialchars(isset($_POST['address']) ? $_POST['address'] : $userdata['address']); ?></textarea></td>
</tr>

/manager/includes/lang/english.inc.php
Add new input labels in here, e.g.

$_lang["user_address"] = 'Address';

/manager/processors/save_web_user.processor.php
In the section starting $id = intval($_POST['id']); add in your custom fields, e.g.

$modx->db->escape($_POST['address'])

Then add in the new field in the insert and update lines starting with:

$sql = "INSERT INTO $dbase.`"
$sql = "UPDATE $dbase.`"

Don't forget to add corresponding fields to the web_user_attributes database table.

This will also apply to manager fields – just use the appropriate files.

About Keiron

Web Developer based in the UK. Click here if you want to work with me