0

Okay, so 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 seperate file correct? Or would it not be worth it, given 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?

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

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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