Hi,
I’m new to these forums, but have used ModX a couple of times already and am a big fan. I really needed to be able to edit the username as well as the other information for a profile. While YankeeDeuce’s mod is helpful, it obviously only works for fields in the same table. Here’s what I came up with. Keep in mind that I’m a major newbie when it comes to PHP or any server-side scripting. Maybe the more experienced members could come up with a much cleaner way of doing this...
In webeditprofile.inc.php
Line 11 - 12
$result = $modx->db->select("*",$modx->getFullTableName('web_user_attributes'),"internalKey = ".$uid);
$userdata = $modx->db->getRow($result);
Add After
$newresult = $modx->db->select("*",$modx->getFullTableName('web_users'),"id = ".$uid);
$usernamedata = $modx->db->getRow($newresult);
Line 25
$tpl = str_replace("[+username+]",$_SESSION['webShortname'],$tpl);
Add After
$tpl = str_replace("[+username_edit+]",$usernamedata['username'],$tpl);
Line 78
$fullname = $_POST['fullname'];
Add
Before
$username_edit = $_POST['username_edit'];
Line 84
$fields = array("fullname"=>$modx->db->escape($fullname),
Add
Before
$usernamefields = array("username"=>$modx->db->escape($username_edit));
Lines 97 - 101
$rs1 = $modx->db->update($fields,$modx->getFullTableName('web_user_attributes'),"internalKey = ".$uid);
if(!$rs1) {
$output = webLoginAlert("Unable to update profile at this time!").$tpl;
return;
}
Add After
$rs = $modx->db->update($usernamefields,$modx->getFullTableName('web_users'),"id = ".$uid);
if(!$rs) {
$output = webLoginAlert("Unable to update profile at this time!").$tpl;
return;
}
And don’t forget to add the input field to the table
<tr>
<td>Username:</td>
<td>
<input type="text" name="username_edit" class="inputBox" style="width:300px" size="20" maxlength="100" value="[+username_edit+]"></td>
</tr>
<tr>
I apologize for the messy code. I would love it if one of the experienced coders here added this functionality to this snippet. Feel free to do whatever you want with this, but don’t ask me for help. I’m happy that it works, but I don’t entirely know why it does. (Note: the line numbers are from the original code. I didn’t increment them as I added code to the file).
Here’s the file that I’m using.