We are currently using Joomla's user class to create new staff, In our staff page. It works well and successfully creates the new user account. But we have an issue. Because the user account button at the top of screen also relies on calls to a Joomla user object, once we create a new user, the moment after creation the name displayed is that of the user we just created. Now once you refresh or move to another page the issue disappears.
If we wish to avoid the confusion this instance might cause, it might make sense to move the method we use to create new users out of the page and into a separate file; correct? Or would it not be worth it, given that it has no other effects but a temporary name that is resolved without any real effort on the part of the user?
This is the code we use:
$udata = array(
"name"=>$_POST['firstName'].' '.$_POST['surName'],
"username"=>$_POST['username'],
"password"=>$_POST['password'],
"password2"=>$_POST['password'],
"email"=>$_POST['companyEmail'],
"block"=>0,
"groups"=>array("2","6")
);
$user = new JUser;
//Write to database
if(!$user->bind($udata)) {
echo "<script>alert('Could not bind data. Error: ".$user->getError()."</script>";
}
if (!$user->save()) {
echo "<script>alert('Could not save user. Error: " . $user->getError()."</script>";
} else {
echo "<script>alert('New User $user->id Created');</script>";
// Script Here to enter additional details in usg_usg_staff table
}
Or would it be wiser to remove the user->name
call?