0

I wanted some input as to what the best way to handle this would be. I have a submit button and a normal button inside a form. I don't want to do a submit on my delete button for the form. Is setting a link outside of the button to carry over into another file using a $_GET parameter the best way here? Basically, take the GET parameter in the php file and if its true, then do my delete functionality. Is there a better way here?

e.g. <a href="delete.php?delete=true"><input type="button" value="Delete Item" /></a>
wowzuzz
  • 1,398
  • 11
  • 31
  • 51

2 Answers2

1

GET requests should be used when accessing data (SELECT). POST requests should be used when modifying data (UPDATE, CREATE, DELETE). i.e. You shouldn't be using a GET request to delete a system resource.

Wayne Whitty
  • 19,513
  • 7
  • 44
  • 66
  • So should I wrap another form around my additional button? – wowzuzz Nov 28 '12 at 16:11
  • @wowzuzz It's hard to say because I'm not entirely sure what you're trying to achieve. Does this deletion have to occur before the form is submitted? Are the form submission and table row deletion directly related / reliant on one another? – Wayne Whitty Nov 28 '12 at 16:14
  • The page I am currently working on has an item that I can update or delete. There is two methods here. Updating and deleting. I update this form using the POST method. The deletion should take place after the button has been clicked. The form submission and table row deletion don't have to be connected. – wowzuzz Nov 28 '12 at 16:18
  • @wowzuzz Why not create two separate forms for UPDATE and DELETE? – Wayne Whitty Nov 28 '12 at 16:19
  • The two forms are on the same page now. One for deleting and one for updating. I think thats what I will do. – wowzuzz Nov 28 '12 at 16:21
0

I had a similar thing, and there where two methods I used:

The first was that I used a standard button which had the onclick attribute set to a javascript function that would change the value of a hidden input and would then submit the form.

The second was a submit button, but following this question: Position div box at the end of after ensuing elements, I had the main form submit (that would save) at the beginning of the form, which then appeared at the bottom of the form. This mean't that when if the enter button was pressed, the delete submit wouldn't be clicked (and detected by the script), but the main submit would be.

Community
  • 1
  • 1
topherg
  • 4,203
  • 4
  • 37
  • 72