To check if the user has performed a search, you can check if the search input form was posted:
$search = isset($_POST['search']) ? $_POST['search'] : '';
Then, you can just append the value to the URL:
$api_url = 'https://api.habboapi.net/badges?per_page=540&description=' . $search;
I’m using the following api – https://habboapi.net/docs/badges/request (PHP Version) to pull Images from a Website.
It works https://beta.habbox.co/#content/habbo/badges and I have it displaying 540 “badges”.
I’d like to add a search feature so you can search using the URL Parameters within the API
e.g. https://api.habboapi.net/badges?per_page=540&description=childline pulls all badges with any mention of the Word “Childline” within the description, or image name.
That way, when a user searches for keywords or descriptions, they get an output from the API.
Here is my current code:
<div class="box">
<form action="" method="post" id="10">
<div align="center">
<input style="width: 930px; height: 25px; padding: 5px; font-size: 16px; background: -webkit-linear-gradient(top, #EEEEEE , #fff); border: 1px solid #dddddd;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;" type="text" name="search" id="search" placeholder="Search Badges...">
</div>
<input style="display: none;" class="button" type="submit" name="submit" value="Submit">
</form>
</div> <br>
<div class="box" align="center">
<?php
// Fetch API Url
$api_url = 'https://api.habboapi.net/badges?per_page=540';
// Look for Badges
$badges = json_decode(file_get_contents($api_url), true);
foreach($badges['data'] as $badge){
// Echo out badges
echo '<div id="rounded" style="width:44px; height: 44px;"><img src="' . $badge['image'] . '" /></div>';
}
?>
</div>
I’m just in the early stages of learning PHP and really have no idea where to go, but I’m willing to learn and would appreciate the help on this!