XF 2.1 Set id from username

gaga

Member
Hello i build simple custom add-on but i have a problem
In my add-on i need to invite users. I use standard autocomplete but i need from choosed username get just user_id and write to my addon db table
Thanks for helping
 

gaga

Member
Ok i have this field:
Code:
                    <xf:textboxrow name="u_id"  ac="single"
                                       placeholder="{{ phrase('username') }}"
                                       label="{{ phrase('user_name') }}" />

and this controller:
Code:
 $userRepo = $this->repository('XF:User');
 
 $input = $this->filter([
            'u_id' => 'unum'

        ]);
 
 
         $recipient = $userRepo->getUserByNameOrEmail($input['u_id']);
        if (!$recipient)
        {
            return $this->notFound(\XF::phrase('requested_user_not_found'));
        }

But not write value in db for u_id
 

kick

Well-known member
'u_id' => 'unum' should be 'u_id' => 'str'
HTML:
<xf:textboxrow 
                           ac="single"
                           placeholder="{{ phrase('username') }}"
                           label="{{ phrase('user_name') }}"
                           name="u_id" />
PHP:
            $input = $this->filter([
                'u_id' => 'str',
            ]);
            /** @var User $userRepo */
            $userRepo = $this->repository('XF:User');
            $user = $userRepo->getUserByNameOrEmail($input['u_id']);
            if (!$user) {
                return $this->error(\XF::phrase('requested_user_not_found'));
            }
 
Last edited:

gaga

Member
'u_id' => 'unum' should be 'u_id' => 'str'
HTML:
<xf:textboxrow
                           ac="single"
                           placeholder="{{ phrase('username') }}"
                           label="{{ phrase('user_name') }}"
                           name="u_id" />
PHP:
            $input = $this->filter([
                'u_id' => 'str',
            ]);
            /** @var User $userRepo */
            $userRepo = $this->repository('XF:User');
            $user = $userRepo->getUserByNameOrEmail($input['u_id']);
            if (!$user) {
                return $this->error(\XF::phrase('requested_user_not_found'));
            }
No error but u_id field is just default value 0 no changed.
 
Top