Open sainwind opened 8 years ago
Hi Sainwind,
I don't know if this can still be interesting for you or other users.
I walked into the same situation as you. I'm handling this with a PHP file that queries to the database.
In the PHP file you can use the GET variable 'term'
PHP file:
$turnBackArray = [];
//We build up the full search array from the database
//We can assign unique values to ID / LABEL / VALUE where the user can search on
//The value of 'value' will be filled in in a tag
foreach($users as $u){
array_push($turnBackArray, [
"id" => $u["name"], "label" => $u["name"] ." - ". $u["id"], "value" => $u["emailaddress"]]);
}
//We get the search term from the field
$searchTerm = $_GET["term"];
//We build up the output array
$outputArray = [];
foreach($turnBackArray as $a){
$added = false;
if(substr($a["id"], 0, strlen($searchTerm)) === $searchTerm){
array_push($outputArray, $a);
$added = true;
}
if(!$added && substr($a["label"], 0, strlen($searchTerm)) === $searchTerm){
array_push($outputArray, $a);
$added = true;
}
if(!$added && substr($a["value"], 0, strlen($searchTerm)) === $searchTerm){
array_push($outputArray, $a);
$added = true;
}
}
//We send the file back to the input to show the results
echo json_encode($outputArray);
HTML file:
$('#to').tagsInput({
'autocomplete_url': 'https://agency.blog-ladbrokes.be/api/getTo.php',
'defaultText':'Add a recipient',
'interactive':true,
'delimiter':[','],
'removeWithBackspace':true
});
i want get user input value, and can pass this value to system make a query,like user input "a",i will query data startwith "a",not all data.Thanks a lot! How could i get the value?