php - Typeahead form action -


i'm trying make search input user can enter keyword , autocomplete results database.

i've accomplished make search input autocomplete , show results, thing missing make when user presses name re-direct page result.

in case need pass results id parameter in url.

html

<form action="" method="post">     <input type="text" name="clients" id="clients" data-provide="typeahead">     <input type="submit" name="clients_submit" value="search"> </form> 

jquery

var clients = new bloodhound({     datumtokenizer: bloodhound.tokenizers.obj.whitespace('client_name'),     querytokenizer: bloodhound.tokenizers.whitespace,     remote: {         url: './core/views/clients.php?query=%query',         wildcard: '%query'     } });  clients.initialize();  $("#clients").typeahead({     hint: true,     highlight: true,     minlength: 2 },{     name: 'clients',     displaykey: 'client_name',     source: clients.ttadapter() }); 

php

header('content-type: application/json');  if(!isset($_get['query'])){     echo json_encode([]);     exit(); }      $conn = new pdo('mysql:host=localhost;dbname=autocomplete;charset=utf8', "root", "root");     $conn->setattribute(pdo::attr_errmode, pdo::errmode_exception);      $clients = $conn->prepare("select client_id, client_name crm_clients client_name :query");      $clients->execute([         'query' => "{$_get['query']}%"     ]);      echo json_encode($clients->fetchall()); 


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -