2

Dont' know why but since Joomla 3.9.22 (or 3.9 ?), when I create a User with User Class, I have the error "Please enter your name". But the name field is not empty.

Here is my simple code :

$udata = array(
            "name"=>$data['name'],
            "username"=>$data['user'],
            "password"=>$data['pass'],
            "email"=>$data['email'],
            "block"=>0,
            "groups"=>array("1","2"),
            "params"=>array(
                "admin_style" => "",
                "admin_language" => "",
                "language" => 'fr-FR',
                "editor" => "",
                "helpsite" => "",
                "timezone" => ""

            ),
            "requireReset"=>1
        );



        $user = new User;
        $user->save();

        if(!$user->bind($udata)) {


            return false;


        }

Here is the User Object:

object(Joomla\CMS\User\User)[440]
  protected 'isRoot' => null
  public 'id' => int 0
  public 'name' => string 'Test TEST' (length=9)
  
  ...    

  protected '_errors' => 
    array (size=1)
      0 => string 'Veuillez saisir votre nom.' (length=26)

Someone could help me? Because I don't understand.

Thanks,

2

It looks like that You are actually just using a wrong sequence when you try to save a new user to the database.

In the correct sequence you first bind() the $data (user data array) to the new User object and then you can save() it. So your new user is not stored in the database by your code above.

The correct sequence:

$user = new User;
$user->bind($udata);
$user->save();

In an older post here you can see how you should apply exceptions (if you would like to): https://stackoverflow.com/questions/1904809/how-can-i-create-a-new-joomla-user-account-from-within-a-script

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.