Input Type = Image

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Tim
Posts: 37
Joined: Fri Jun 10, 2011 12:49 am

Input Type = Image

Post by Tim »

Hmm, any idea why this code won't work in Firefox and Internet Explorer, but works in Chrome just fine?

Code: Select all

<?php
if (isset($_POST['harvestable']))
{
   echo "Success!";
}
?>

<form action="harvest.php" method="post">
<table border ="0" cellspacing="50">
<tr>
<td><center><input type="image" name="harvestable" value="Blue Lupine" src="/images/items/blue_lupine.png"><br>Blue Lupine</center></td>
</tr>
</table>
</form>
Or is there another way I can have this work?

I think it's about time I start digging into Jquery ... Advice?

Thank you!
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Input Type = Image

Post by Xaleph »

Well, the code is just messed up, that`s why it doesn`t work.

First of, close an input type image propery using the /> self closing tag. Second, an input type image doesn`t need a value ( you are using an image remember ? ) and lastly, don`t use <center>. It`s old, if you want something aligned, use css ( text-align: center; )
Tim
Posts: 37
Joined: Fri Jun 10, 2011 12:49 am

Re: Input Type = Image

Post by Tim »

Thanks for the fast reply.

I need a value because that's how I'm going to retrieve everything out of the database.

Code: Select all

<?php
if (isset($_POST['harvestable']))
{
   $harvestable_name = $_POST['harvestable'];
		
   $harvestable_info_1 = "SELECT * FROM items WHERE name = '$harvestable_name'";
   $harvestable_info_2 = mysql_query($harvestable_info_1) or die ("System: Unable to retrieve harvestable information.");
   $harvestable_info_3 = mysql_fetch_array($harvestable_info_2);
}
?>

<form action="harvest.php" method="post">
<table border ="0" cellspacing="50">
<tr>
<td><input type="image" name="harvestable" value="Blue Lupine" src="/images/items/blue_lupine.png" /><br>Blue Lupine</td>
</tr>
Xaleph
Posts: 897
Joined: Mon Feb 07, 2011 2:55 am

Re: Input Type = Image

Post by Xaleph »

Use input type submit

In your css you can style the button to use an image as well. Jut give it a class or id and in your css:

#someID , .someClass {
height: (height of your image)px;
width: (width of your image)px;
background-image: url(the_url_to_the_image);
text-indent: -9999px;
}

Anyway, value is possible, but why use it like that? In a submit button ( image) ? Maybe use a input type="hidden" to give that sort of information.
Post Reply

Return to “Beginner Help and Support”