getting
Use of undefined constant name - assumed 'name' (this will throw an Error in a future version of PHP)
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I am trying jquery typeahead
I add jquery
typeof $.typeahead === 'function' && $.typeahead({
input: '.js-typeahead-hockey_v2',
minLength: 1,
maxItem: 8,
maxItemPerGroup: 6,
order: "asc",
hint: true,
searchOnFocus: true,
blurOnTab: false,
matcher: function (item, displayKey) {
if (item.id === "BOS") {
// Disable Boston for X reason
item.disabled = true;
}
// Add all items matched items
return true;
},
multiselect: {
limit: 10,
limitTemplate: 'You can\'t select more than 10 teams',
matchOn: ["id"],
cancelOnBackspace: true,
data: function () {
var deferred = $.Deferred();
setTimeout(function () {
deferred.resolve([{
"matchedKey": "name",
"name": "Canadiens",
"img": "canadiens",
"city": "Montreal",
"id": "MTL",
"conference": "Eastern",
"division": "Northeast",
"group": "teams"
}]);
}, 2000);
deferred.always(function () {
console.log('data loaded from promise');
});
return deferred;
},
callback: {
onClick: function (node, item, event) {
console.log(item);
alert(item.name + ' Clicked!');
},
onCancel: function (node, item, event) {
console.log(item);
alert(item.name + ' Removed!');
}
}
},
templateValue: "{{name}}",
display: ["name", "city"],
emptyTemplate: 'no result for {{query}}',
source: {
teams: {
url: "/jquerytypeahead/hockey_v2.json"
}
},
callback: {
onClick: function (node, a, item, event) {
console.log(item.name + ' Added!')
},
onSubmit: function (node, form, items, event) {
event.preventDefault();
alert(JSON.stringify(items))
}
},
debug: true
});
I add HTML
<form id="form-hockey_v2" name="form-hockey_v2">
<div class="typeahead__container">
<div class="typeahead__field">
<span class="typeahead__query">
<input class="js-typeahead-hockey_v2" name="hockey_v2[query]" type="search" placeholder="Search" autocomplete="off">
</span>
<span class="typeahead__button">
<button type="submit">
<i class="typeahead__search-icon"></i>
</button>
</span>
</div>
</div>
</form>
but don't know where add PHP ?????????????????????
header('Content-Type" => application/json');
echo json_encode(array(
array(
"name" => "Ducks",
"img" => "ducks",
"city" => "Anaheim",
"id" => "ANA",
"conference" => "Western",
"division" => "Pacific",
"disabled" => true
),
array(
"name" => "Thrashers",
"img" => "thrashers",
"city" => "Atlanta",
"id" => "ATL",
"conference" => "Eastern",
"division" => "Southeast"
),
array(
"name" => "Bruins",
"img" => "bruins",
"city" => "Boston",
"id" => "BOS",
"conference" => "Eastern",
"division" => "Northeast"
),
array(
"name" => "Sabres",
"img" => "sabres",
"city" => "Buffalo",
"id" => "BUF",
"conference" => "Eastern",
"division" => "Northeast"
),
array(
"name" => "Flames",
"img" => "flames",
"city" => "Calgary",
"id" => "CGY",
"conference" => "Western",
"division" => "Northwest"
),
array(
"name" => "Hurricanes",
"img" => "hurricanes",
"city" => "Carolina",
"id" => "CAR",
"conference" => "Eastern",
"division" => "Southeast"
),
array(
"name" => "Blackhawks",
"img" => "blackhawks",
"city" => "Chicago",
"id" => "CHI",
"conference" => "Western",
"division" => "Central",
"disabled" => true,
),
array(
"name" => "Avalanche",
"img" => "avalanche",
"city" => "Colorado",
"id" => "COL",
"conference" => "Western",
"division" => "Northwest"
),
array(
"name" => "Bluejackets",
"img" => "bluejackets",
"city" => "Columbus",
"id" => "CBJ",
"conference" => "Western",
"division" => "Central"
),
array(
"name" => "Stars",
"img" => "stars",
"city" => "Dallas",
"id" => "DAL",
"conference" => "Western",
"division" => "Pacific"
),
array(
"name" => "Red Wings",
"img" => "redwings",
"city" => "Detroit",
"id" => "DET",
"conference" => "Western",
"division" => "Central"
),
array(
"name" => "Oilers",
"img" => "oilers",
"city" => "Edmonton",
"id" => "EDM",
"conference" => "Western",
"division" => "Northwest"
),
array(
"name" => "Panthers",
"img" => "panthers",
"city" => "Florida",
"id" => "FLA",
"conference" => "Eastern",
"division" => "Southeast"
),
array(
"name" => "Kings",
"img" => "kings",
"city" => "Los Angeles",
"id" => "LAK",
"conference" => "Western",
"division" => "Pacific"
),
array(
"name" => "Wild",
"img" => "wild",
"city" => "Minnesota",
"id" => "MIN",
"conference" => "Western",
"division" => "Northwest"
),
array(
"name" => "Canadiens",
"img" => "canadiens",
"city" => "Montreal",
"id" => "MTL",
"conference" => "Eastern",
"division" => "Northeast"
),
array(
"name" => "Predators",
"img" => "predators",
"city" => "Nashville",
"id" => "NSH",
"conference" => "Western",
"division" => "Central"
),
array(
"name" => "Devils",
"img" => "devils",
"city" => "New Jersey",
"id" => "NJD",
"conference" => "Eastern",
"division" => "Atlantic"
),
array(
"name" => "Islanders",
"img" => "islanders",
"city" => "New York",
"id" => "NYI",
"conference" => "Eastern",
"division" => "Atlantic"
),
array(
"name" => "Rangers",
"img" => "rangers",
"city" => "New York",
"id" => "NYR",
"conference" => "Eastern",
"division" => "Atlantic"
),
array(
"name" => "Senators",
"img" => "senators",
"city" => "Ottawa",
"id" => "OTT",
"conference" => "Eastern",
"division" => "Northeast"
),
array(
"name" => "Flyers",
"img" => "flyers",
"city" => "Philadelphia",
"id" => "PHI",
"conference" => "Eastern",
"division" => "Atlantic"
),
array(
"name" => "Coyotes",
"img" => "coyotes",
"city" => "Phoenix",
"id" => "PHX",
"conference" => "Western",
"division" => "Pacific"
),
array(
"name" => "Penguins",
"img" => "penguins",
"city" => "Pittsburgh",
"id" => "PIT",
"conference" => "Eastern",
"division" => "Atlantic"
),
array(
"name" => "Sharks",
"img" => "sharks",
"city" => "San Jose",
"id" => "SJS",
"conference" => "Western",
"division" => "Pacific"
),
array(
"name" => "Blues",
"img" => "blues",
"city" => "St. Louis",
"id" => "STL",
"conference" => "Western",
"division" => "Central"
),
array(
"name" => "Lightning",
"img" => "lightning",
"city" => "Tampa Bay",
"id" => "TBL",
"conference" => "Eastern",
"division" => "Southeast"
),
array(
"name" => "Maple Leafs",
"img" => "mapleleafs",
"city" => "Toronto",
"id" => "TOR",
"conference" => "Eastern",
"division" => "Northeast"
),
array(
"name" => "Canucks",
"img" => "canucks",
"city" => "Vancouver",
"id" => "VAN",
"conference" => "Western",
"division" => "Northwest"
),
array(
"name" => "Capitals",
"img" => "capitals",
"city" => "Washington",
"id" => "WSH",
"conference" => "Eastern",
"division" => "Southeast"
),
array(
"name" => "Jets",
"img" => "jets",
"city" => "Winnipeg",
"id" => "WPG",
"conference" => "Eastern",
"division" => "Southeast"
)
));
Please or to participate in this conversation.