# Send a POST off a link, not a button

**URL:** <https://www.ruby-forum.com/t/send-a-post-off-a-link-not-a-button/60075>\
**Category:** Rails\
**Created:** [May 10, 2006, 12:11am UTC](https://www.ruby-forum.com/t/send-a-post-off-a-link-not-a-button/60075 "2006-05-10T00:11:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![samonderous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@samonderous](https://www.ruby-forum.com/u/samonderous)\
**Post date:** [May 10, 2006, 12:11am UTC](https://www.ruby-forum.com/t/send-a-post-off-a-link-not-a-button/60075/1 "2006-05-10T00:11:39Z")

</div>

Hi,

Got a question about how the book suggests sending POST requests using a  
form whenever one intents to change some database state. So I converted  
a  
bunch of links to forms which ended up creating buttons. I was  
wondering if  
there was a way to keep them links rather than buttons but still use  
POST in  
a form?

thanks.

---

<div class="post-metadata">

**Author:** ![samonderous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@samonderous](https://www.ruby-forum.com/u/samonderous)\
**Post date:** [May 10, 2006, 12:35am UTC](https://www.ruby-forum.com/t/send-a-post-off-a-link-not-a-button/60075/2 "2006-05-10T00:35:49Z")

</div>

Am 10.05.2006 um 00:11 schrieb Sam D.:

> Hi,
> 
> Got a question about how the book suggests sending POST requests  
> using a form whenever one intents to change some database state.  
> So I converted a bunch of links to forms which ended up creating  
> buttons. I was wondering if there was a way to keep them links  
> rather than buttons but still use POST in a form?

Call a JavaScript that does an XmlHttpRequest (aka AJAX request)  
which is submitted via POST.

\*m

---

<div class="post-metadata">

**Author:** ![samonderous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@samonderous](https://www.ruby-forum.com/u/samonderous)\
**Post date:** [May 10, 2006, 1:42am UTC](https://www.ruby-forum.com/t/send-a-post-off-a-link-not-a-button/60075/3 "2006-05-10T01:42:57Z")

</div>

Sam D. wrote:

> Hi,
> 
> Got a question about how the book suggests sending POST requests using  
> a form whenever one intents to change some database state. So I  
> converted a bunch of links to forms which ended up creating buttons.  
> I was wondering if there was a way to keep them links rather than  
> buttons but still use POST in a form?  
> Try link\_to(“Destroy!”, {:action =\> ‘destroy’}, :post =\> true).

This will automagically create the javascript to turn the link in to a  
POST method.

---

<div class="post-metadata">

**Author:** ![samonderous](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3da27b/32.png) [@samonderous](https://www.ruby-forum.com/u/samonderous)\
**Post date:** [May 10, 2006, 1:30am UTC](https://www.ruby-forum.com/t/send-a-post-off-a-link-not-a-button/60075/4 "2006-05-10T01:30:39Z")

</div>

Manuel H. \<purestorm@…\> writes:

> > rather than buttons but still use POST in a form?
> 
> Call a JavaScript that does an XmlHttpRequest (aka AJAX request)  
> which is submitted via POST.
> 
> \*m

Or easier, your link should look like this:

Link Name

This submits the first form on the page. You can also specify forms by  
name or  
id I think, but you typically only have one form per page anyway.
