Trying to make simple search with image result in php | html

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ricardogarcia
Forum Newbie
Posts: 3
Joined: Wed Dec 31, 2014 3:47 pm

Trying to make simple search with image result in php | html

Post by ricardogarcia »

Okay here is what I'm trying to do...

--------------------------------------------------primary function of what I'm trying to do-----------------------------------------------------------

simply....

if the user picks a zipcode from $loc1 then image $image1(nextday) will show... if user pick a zipcode from $loc2 than $image2(2nd-Day)will hopefully appear under the search box..

i hope that no page "redirect" is necessary... since images are displayed under search box area...

---------------------------------------------------------------------PHP--Form-------------------------------------------------------------------------------

[syntax=php]<?php

$zipcode = $_POST['zipcode'];

$loc1 = array (80013,80015,80126,80127,80128,80129,80130,80134,80135,80138,80160,80161,80162,80163,80165,80166,804 33,80453,80465,80470);

$loc2 = array (80023,80025,80136,80137,80138,80139,80140,80144,80145,80148,80140,80141,80142,80143,80145,80146,804 43,80443,80445,80440);

// need to add whatever validation/sanitation of zip code value here

$image01 = "Next--Day-img.png";
$image02 = "2nd--Day-img.png";
$image03 = "2-3--Day.png";

$image1 = "<img src=img/$image01.png>";
$image2 = "<img src=img/$image02.png>";
$image3 = "<img src=img/$image03.png>";


if(in_array($zipcode, $loc1)) {
echo $image1;
$width = 100;
$height = 662;

}

else if(in_array($zipcode, $loc2)) {
echo $image2;
$width = 100;
$height = 662;


}
else {
echo $image3;
$width = 100;
$height = 662;


$form['#zipcode'] = FALSE;
exit();
}
?>[/syntax]
---------------------------------------------------------------------PHP--Form--End-------------------------------------------------------------------------



---------------------------------------------------------------------HTML--Form-------------------------------------------------------------------------------


[syntax=html]<div class="panel">
<div class="panel-content">

<form id="zipcode" action="<?php echo $_SERVER['PHP_SELF']; ?>" method='POST'>

<input type='text' size="6" maxlength="5" id='searchbar' class='searchbar2'name='zipcode'>
<div id="actions">

<input type='submit' value='Search' onclick="submitclick(); return false;" id='submitbutton' class='zipcode_button'>
<td><id="zipcodeError" value='' class="zipcode_button"/></td>

</div>
</form>
</html>[/syntax]
---------------------------------------------------------------------HTML--Form--End----------------------------------------------------------------------------
ricardogarcia
Forum Newbie
Posts: 3
Joined: Wed Dec 31, 2014 3:47 pm

Re: Trying to make simple search with image result in php |

Post by ricardogarcia »

This is really all i'm trying to do..



simply....

if the user picks a zipcode from $loc1 then image $image1(nextday) will show...

if user pick a zipcode from $loc2 than $image2(2nd-Day)will hopefully appear under the search box..

i hope that no page "redirect" is necessary... since images are displayed under search box area...
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Trying to make simple search with image result in php |

Post by Celauran »

If you don't want the page to reload, just use an AJAX request. Attach a listener to the zip code field's keyup event and once the length of the input hits 5 characters, fire off the request. Your PHP script can determine which image to display and then send that back to the AJAX call to update the form.
Post Reply