forthrin
forthrin

Reputation: 2777

POST when clicking an image

I have a "delete" icon with a relative position in the upper-right corner of a photo. When the icon is clicked, the photo should be deleted on the server.

According to HTTP conventions, this is a destructive action which should be done with POST. So a normal <img href> can not be used since it will cause a GET, which is more insecure.

What is the simplest way to make the icon perform a POST that does not exclude Internet Explorer 8? I am currently looking at:

<form method="post" action="script.php">
<img src="photo.jpg"/>
<input name="delete" type="image" src="/image/delete.png"/>
</form>

Or, is it acceptable to use a href in this situation?

(EDIT: Is it more acceptable when the script is only available to an authenticated administrator?)

Upvotes: 0

Views: 74

Answers (2)

Samuel
Samuel

Reputation: 91

<button type="submit" name="testsubmit" value="click" 
     style="border:none; background-color:transparent;">
<img src="button.png" alt="test image submit" />
</button>

Upvotes: 0

Samira Khorshidi
Samira Khorshidi

Reputation: 942

you should use this code

<form method="post" action="script.php">
<button type="submit" style="background:photo.jpg"/>
<input name="delete" type="image" src="/image/delete.png"/>
</form>

so you can use your photo as background,because when you want submit a form you shold have a input or button whith type submit

Upvotes: 1

Related Questions