Get Image Results from API using PHP - php

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!

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;

Related

Trying to create a submission form with preview

I am trying to make this form be able to submit a post and create a page with auto indexing and also be able to preview the page being created before hand. Can someone help? Thank you in advance, I am pretty bad with PHP files.
#wrapper{
margin: 0 auto;
margin-top: 200px;
padding-left: 50px;
padding-right: 50px;
padding-bottom: 50px;
padding-top: 50px;
background-color: #2C2C2C;
position: relative;
width: 70%;
max-width: 1250px;
min-width: 300px;
z-index: 1;
color: white;
text-decoration-color: white;
box-shadow: 0px 2px 20px 5px #000;
}
.form-control .header {
width: 90%;
outline: inset #6B6B6B;
margin: 5px;
}
<div align="center" id="wrapper">
<h2>Welcome Back <Insert Name>!</h2>
<form id="submission" method="post" action="submission-handler.php" enctype="multipart/form-data">
Blog Title:<center></center>
<br>
Blog Content:<center><textarea name="message" class="form-control" placeholder="Type your blog post here" rows="10" required></textarea>
<textarea name="header" type="text" class="form-control" placeholder="Blog Post Header" rows="2" required></textarea>
</center>
<br>
Upload an image: (Not Currently Working)
<center><input type="file" name="filetoupload" id="filetoupload" disabled></center>
<br>
<br>
<hr>
<br>
<br>
<input type="submit" class="form-control submit" value="Preview Post" disabled>
<input type="submit" class="form-control submit" value="Finalize Post" disabled>
</form>
</div>
The actual page looks different than shown up on here. If anybody needs a reference , here
based on your code above your trying to pass a value to another page..
try to put this code in submission-handler.php
<?php
$message = $_POST['message'];
$header = $_POST['header'];
echo $message;
echo "<br>";
echo $header;
?>

PHP posting error

I keep getting a Cannot POST /app/newpost/newpost.php error when i try to post a HTML form and retrieve the data from another HTML page
HTML for the form is:
<div style="text-align:center">
<h1 style="font-size:36px; font-family:verdana;">
Create a new forum post
</h1>
</div>
<form action="newpost.php" method="POST" style="text-align:center">
<P style="font-size:24px; font-family:verdana;">Title: <input type="text" name="title" style="font-size:24px; font-family:verdana;"></P>
<P style="font-size:24px; font-family:verdana;">Description: <input type="text" name="desc" style="font-size:24px; font-family:verdana;"></P>
<input type="submit" action="window.location.href='/app/forum/forum.component.html'" style="background-color: #4CAF50; border: none; color: white; padding: 15px 32px; text-align: left; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer;">
</form>
PHP file is
<?php
if (isset($_POST["submit"]))
{$title = $_POST['title'];
$desc = $_POST['desc']
}
?>
im still very new to PHP someone pls help!
And how to retrieve the posted data on another html page?
You need a web server with PHP installed to test/run your PHP script. You cannot have it run from your file system directory. Depending on your environment you might want to installed something called WAMP, XAMP or MAMP.
Looks like there ; missing
i have changed you code to bellow, it should run now
<?php
if (isset($_POST["submit"]))
{
$title = $_POST['title'];
$desc = $_POST['desc'];
}
?>
try this
I think having action="newpost.php" as an attribute in the form tag and action="window.location.href='/app/forum/forum.component.html'" as an attribute in the input type="submit" tag is a contradiction. You might want to try to erase one of them.

Buttons and texts move back to original place

I have set when user types something in the search box, the suggestions will appear.
When suggestions appear, it will push the buttons and texts below down as I set its position relative.
But when user delete those words in the search box and the suggestion list disappears, the buttons and texts below the suggestion list did not move back to the original place.
How can I let the buttons and texts below the suggestion list move back to the original place when user delete those words in search box?
This is my current code:
<?php
include 'script_suggestion.php';
include 'script_close_suggestion_box.php';
?>
<html>
<head>
<title>
Brandon's Search Engine
</title>
<style type="text/css">
#suggestion {
border: 1px solid black;
visibility: hidden;
position: relative;
background-color: transparent;
z-index: 10;
}
.suggestion a {
font-size: 12pt;
color: black;
text-decoration: none;
display: block;
width: 648px;
height: auto;
text-align: left;
padding: 10px;
}
.suggestion a:hover {
background-color: #dddddd;
width: 644px;
padding: 2px;
}
</style>
</head>
<body>
<form method="GET" action="search.php" name="q">
<table align="center">
<div>
<h1><center>Brandon's Search Engine</center></h1>
</div>
<div align="center">
<input type="text" name="q" id="q" class="q" style="height: 27px; width: 650px; padding: 2px" placeholder="Search Now"
onkeyup="getSuggestion(this.value)" autocomplete="off" autoFill="on" onblur="closeBox()"/>
<script>document.getElementById('q').focus()</script>
<div id="suggestionBox" style="visibility: collapse;">
<div id="suggestion" style="width: 645px; text-align: left; padding: 2px;">
</div>
</div>
</div>
<br />
<div align="center">
<input type="submit" value="Search" name="submit" style="height: auto; width: 60px; padding: 2px" />
<input type="reset" value="Clear" onclick="closeBox()" style="height: auto; width: 50px; padding: 2px" />
</div>
<div align="center">
Can't find your site? <br /> Insert here.
</div>
</table>
<input type="hidden" name="page" value="1" />
</form>
</body>
</html>
Thanks in advance.
On your function in your onkeyup, you can check the text value and if that was empty change css position of your element to original:
function getSuggestion(value){
if(!value.length()){
//change to original place
}
.
.
.
}
I hope to help

applying style to html dynamically from user input

I have a form that the user fills out with various items, including choosing a background. When they press a button to preview the form, I send them to another .php page which pops up an iframe and assembles all the form parts into a letter. My problem is getting the background to populate. Here is how I am trying to get the background to display ($stationery is whatever the user asked for, with input cleaned up). I'm close, because if I cheat and code
<div style="width: 550px; height: 550px; padding: 15px; background-image:url(images/stationery/birthday.jpg);">
It works fine. But, as I said, that's cheating :-)
$final = "url(images/stationery/" . $stationery . ".jpg);" ;
<div style="width: 550px; height: 550px; padding: 15px; background-image:" . $final . ";>"
<h3>Message Preview</h3>
.......
but the background doesn't show and I'm not getting any errors. Firebug however, looks horrendous:
<div <h3="" "="" ";="" $final;="" .="" background-image:\"="" 15px;="" padding:="" height:="" 550px;="" style="\"width:">
Can someone point me in the right direction? Thanks
<?php
$final = "url('images/stationery/" . $stationery . ".jpg');";
?>
<div style="width: 550px; height: 550px; padding: 15px; background-image: <?php print $final; ?>">
<h3>Message Preview</h3>
<!--Don't forget to close the div-->
</div>
Or if you want it all to be ran through the PHP interpreter:
<?php
$final = "url('images/stationery/" . $stationery . ".jpg');";
print '<div style="width: 550px; height: 550px; padding: 15px; background-image: ' . $final . '">';
print '<h3>Message Preview</h3>';
// Don't forget to close the div...
print '</div>';
?>
Better yet:
<div style="width: 550px; height: 550px; padding: 15px; background-image: url('images/stationery/<?php print $stationery; ?>.jpg');">
<h3>Message Preview</h3>
<!--Don't forget to close the div-->
</div>

using php and java script in a form

I am a little bit lost. What I want to achieve is:
my own custom button
change onMouseOver etc'
keep it's size
post the information to a php server side code
What I'm missing is:
The post - I couldn't figure out how to combine js & php
The Button size - my code sets a size for the original button but after the rollover it changes
The code:
<html>
<head>
</head>
<body>
<script>
function form_on_click(frm)
{
document.buttonMore.src='bottom_more_click.JPG';
frm.submit();
}
</script>
<div style="position: absolute; left: 120px; top: 90px; background-image: url(myBackgroundPicture.jpg);
background-repeat:no-repeat; width: 800px; height: 280px; padding: 15px;">
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="whatever" size= "55" height="100" lang="en" dir="ltr" style="margin-top: 188px; margin-left: 95px; height: 20px; background-color: transparent; border:none;
color: #FFFFFF; font-family: Verdana; font-weight: none; font-size: 18px;">
<a onmouseover="document.buttonMore.src='bottom_more_hover.JPG'"
onmouseout="document.buttonMore.src='bottom_more_reg.JPG'"
onmousedown= "form_on_click(this.form) this.form.submit()"
onmouseup="document.buttonMore.src='bottom_more_hover.JPG'">
<img src="bottom_more_reg.jpg" name="buttonMore" height="30" width="173" border="0" alt="MORE!" style="margin-bottom:-10px; margin-left: 15px; height: 30px; width: 100px;">
</a>
</form>
</div>
</body>
UPDATED:
Oh sure.. excuse me. You're totally right. I don't know where do I have my head.
Try something else, remove this line again
onmousedown= "form_on_click(this.form) this.form.submit()"
And replace it by
href="javascript:form_on_click(this.form);"
Just a suggestion, why don't you use an...
<input type="button" />
...and then customize it in CSS?
EDIT
About the size of the button, are those jpeg files equally sized?
The easiest way would be to use JQuery. All of what you want to do can be done with just a few simple steps in JQuery. The mouseover/out submit all of it and tons more.
I fell in love with JQuery...

Categories