RS7
RS7

Reputation: 2361

Page actions like deleting something or changing status - use a link or a form button?

I have a handful of pages that let me alter the status of things (like changing the status of a listing or deleting an user) and I was wondering: should I use a link or create form buttons for those actions? (without javascript)

What are the pros and cons of each implementation? It seems to me that link is easier to code but form buttons seem more secure.

What do you think?

Upvotes: 2

Views: 95

Answers (2)

JB Nizet
JB Nizet

Reputation: 692181

Non idempotent operations, like creations, updates and deletes are supposed to be done with a POST. So, without JavaScript, a form should be used with a submit button. This at least warns the user, if he refreshes the page after the delete, that the action will be resubmitted.

A useful pattern, to let the user refresh the page after the post and not risk a re-submit, is the redirect after post pattern , also known as post-redirect-get. This makes sure a refresh is possible, and make the browser "forget" about the post in his history, allowing the user to go back without resubmitting the delete.

Upvotes: 3

Rodolfo
Rodolfo

Reputation: 4183

well with css you can make buttons look like links and links look like buttons, so it's mostly a matter of appearance. Personally, I try to use links to indicate movement (to another page, to another part of the page, popup page, etc) and buttons for actions (updates, deletes, 'buy', etc)

Upvotes: 1

Related Questions