How submit a form using input type="image" with php isset
August 18, 2011we can get or post a value of input type="submit" like
// html
<form method="post">
<input type="submit" name="send" value="send now" />
</form>
// php
if(isset($_POST['send'])) echo $_POST['send'];
//result is -> send now
but
if we replace the input type of above example, like :
<input type="image" name="send" src="button.png" />
then result will be empty
The reason is :
An element which input type="image" specifies as image resource to display. And there are two values of x and y (send_x and send_y) which the positions of the mouse where click on the image.
So you can use, like :
// html
<form method="post">
<input type="image" name="send" src="button.png" />
</form>
// php
if(isset($_POST['send_x'])){
// your code here
echo $_POST['send_x'];
}
same as
if(isset($_POST['send_y'])){
// your code here
echo $_POST['send_y'];
echo "<br />";
echo $_POST['send_x'];
}
Make sure you set an image with src attribute. In this case,I used "button.png"
Posted In : php-html