Kevinvhengst
Kevinvhengst

Reputation: 1702

html - how to give a submit button a variable for GET?

i have the following button:

<form method="GET" action="/cms/deleteBlog/">
    <input class="btn btn-danger btn-small" type="submit" name="'.$blogID.'" value="Delete">
</form>

So right now i get the following url:

cms/deleteBlog/?1=Delete

obviously i want something like the following:

cms/deleteBlog/id=1

So i tried the following (which is obviously not working):

name="id='.$blogID.'"

So how do i solve this? i've been looking around on the internet, and i know the solution is quite easy. But i just can't remember the way how it is done!

Upvotes: 0

Views: 9982

Answers (2)

Daniel A. White
Daniel A. White

Reputation: 190907

Add a hidden form field.

<input type="hidden" name="id" value="1" />

Also, you should never use GET to delete or modify data. Read Why should you delete using an HTTP POST or DELETE, rather than GET? for insight.

Upvotes: 3

Rowland Shaw
Rowland Shaw

Reputation: 38130

Why not use a hidden input field, e.g:

<form method="GET" action="/cms/deleteBlog/">
    <input type="hidden" name="id" value="'.$blogID.'">
    <input class="btn btn-danger btn-small" type="submit" value="Delete">
</form>

Or, if you want pretty URLs:

<form method="GET" action="/cms/deleteBlog/id='.$blogID.'">
    <input class="btn btn-danger btn-small" type="submit" value="Delete">
</form>

Upvotes: 1

Related Questions