• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
User search form using AJAX

#1
Hi

I have an input to search for users using their names and it returns the user's id on selection. What I need it to do is to show users (email, full name, phone number).

Screenshot:  [img]<blockquote class=[/img][url=//imgur.com/QwWTz8w][/url]" />




View

Code:
<input type="text" id="getUser" class="form-control" value="" placeholder="<?= lang('Users.Users-startType'); ?>">
<input type="hidden" id="userid" name="userid" value="" >

Js
Code:
$(document).ready(function(){
    // Initialize
    $( "#autouser" ).autocomplete({
        source: function( request, response ) {
            // Fetch data
            $.ajax({
                url: "/users/actions/usrList",
                headers: {'X-Requested-With': 'XMLHttpRequest'},
                type: 'post',
                dataType: "json",
                data: {
                    search: request.term
                },
                success: function( data ) {
                    response( data );
                }
            });
        },
        select: function (event, ui) {
            // Set selection
            $('#autouser').val(ui.item.label); // display the selected text
            $('#userid').val(ui.item.value); // save selected id to input
            return false;
        }
    });
});


Controller
PHP Code:
    public function usrList()
    {
        if ($this->request->isAJAX()) {
            $users = new Auth();
            if(strlen($this->request->getPost('search')) > 3){
                $users $users->havingLike('fullName'$this->request->getPost('search'))->get('3')->getResult();
            }
            foreach ($users as $user) {
                $response[] = array("value" => $user->id"label" => $user->fullName);
            }
            return json_encode($response);
        }
    

I need to auto-populate these fields with the returned values from DB:
Code:
<ul class="list-unstyled">
  <li class="text-dark"><b><?= lang('Users.User-fullName');?></b> </li>
  <li class="text-dark"><b><?= lang('Users.User-email'); ?></b> </li>
  <li class="text-dark"><b><?= lang('Users.User-tel'); ?></b> </li>
</ul>
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.