2

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?

2
  • Could you post your code and where you stuck it? Dec 23, 2017 at 0:55
  • Sure,like I said it's in the usg-staff.php page
    – user11029
    Jan 2, 2018 at 13:32

1 Answer 1

3

I finally resolved the issue. All I had to do was make sure that once the new user was created I set the $user variable back to the active user data by using JFactory::getUser(). I was really over thinking it. It was only displaying the just created user because after creating the user in our joomla table I had not thought to set it back.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.