Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

input type="image" not passing VALUE?

Status
Not open for further replies.

YelloFello

Programmer
Joined
Jun 30, 2003
Messages
4
Location
US
I want the user to select which video to watch by clicking on the image.


This gives me an undefined index error. (url)
<INPUT TYPE="image" SRC="image\path" VALUE="firefight" NAME="url">

This works fine.
<INPUT TYPE="submit" VALUE="firefight" NAME="url">

Seems to me the first one should work. Or am I missing the boat?
Thanks in advance.

 
nope ur first one should work, the error u pointed out is a PHP error???

Known is handfull, Unknown is worldfull
 
This is an HTML question, not a PHP question. It should have been asked in the HTML forum.

Images do not submit values. If you want an image to be clickable, you must surround it with an <A...>...</A> tag.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Sorry, I guess this is an html question.

yes, the error is php.

When the user clicks an image, I want it to pass which image
was selected to

$url = $_POST['url'];

switch($url)
{
case "firefight":
$filepath = "path\firefight.avi";
break;
}


Everything I read says VALUE can be used with image type.
Oh well, I'll just work around it.
Thanks for the help.

 
whats the form method, get or post ?

depending on that you should find either $_GET or $_POST[url] has the value you a...esent like the time, they say. - Henry's Cat.
 
YelloFello:
I don't know what sources you're consulting but the World Wide Web Consortium's [link]web site[/url] does not list a "value" attribute for the IMG tag.

Also, the IMG tag is not a form element. As such, it's unlikely to be passing values.

If you do something like:

<a href="path/to/script.php?somename=somevalue"><IMG src="some/path"></a>

Then when that image is clicked, in the PHP script, $_GET['somename'] will have the value "somevalue".



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
I got it working. Thanks to everyone and especially Sleipnir214.

Now I know why I have never used "image" type input. )

 
Yeah, I dug a little deeper into the inputs of type "IMAGE". Here's what W3 has to say:

When a pointing device is used to click on the image, the form is submitted and the click coordinates passed to the server. The x value is measured in pixels from the left of the image, and the y value in pixels from the top of the image. The submitted data includes name.x=x-value and name.y=y-value where "name" is the value of the name attribute, and x-value and y-value are the x and y coordinate values, respectively.

Given that information, I have a script show_post.php:
Code:
<?php
print '<pre>';
print_r ($_POST);
?>

and test_image_input.html:
Code:
<html>
	<body>
		<form method="POST" action="show_post.php">
			<input type="image" src="star.gif" name="the_image" value="foo">
		</form>
	</body>
</html>

Then I point a browser to test_image_input.html and click on the image, the script returns:

Code:
Array
(
    [the_image_x] => 10
    [the_image_y] => 13
)


If you don't care where on the image the user clicks, I have a workaround.

Modifying test_image_input.php to read:

Code:
<html>
	<body>
		<form method="POST" action="show_post.php" value="foo">
			<input type="image" src="star.gif" name="the_image[red][1][/red]">
			<input type="image" src="hdrlogo.gif" name="the_image[red][2][/red]">
		</form>
	</body>
</html>

Then when I click on the first image, the script returns:

Code:
Array
(
    [the_image] => Array
        (
            [1] => 10
        )

)

So by examining the keys of $_POST['the_image'], you can tell on which image the user clicked, and still use an "image" input.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top