# Link\_to\_function with submit

**URL:** <https://www.ruby-forum.com/t/link-to-function-with-submit/58435>\
**Category:** Rails\
**Created:** [April 21, 2006, 5:23pm UTC](https://www.ruby-forum.com/t/link-to-function-with-submit/58435 "2006-04-21T17:23:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [April 21, 2006, 5:23pm UTC](https://www.ruby-forum.com/t/link-to-function-with-submit/58435/1 "2006-04-21T17:23:20Z")

</div>

I looked everywhere but couldn’t find it.

I don’t want a submit\_tag or image\_submit\_tag but a normal link that  
submits my form.

Normally I would do this with a javascript like

function sendForm ()  
{  
document.forms[0].submit();  
}

but this doesn’t work with form\_remote\_tag

link\_to\_function( ‘Send’ , “sendform();”)

So the question is:  
how do I send my ajax form?

Thanks in advance  
Peet

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [April 21, 2006, 7:41pm UTC](https://www.ruby-forum.com/t/link-to-function-with-submit/58435/2 "2006-04-21T19:41:42Z")

</div>

Peter, I did not try it myself, but I believe you can create helper  
similar to the submit\_to\_remote, but creating link instead of button

looking at the source code

184: def submit\_to\_remote(name, value, options = {})  
185: options[:with] ||= ‘Form.serialize(this.form)’  
186:  
187: options[:html] ||= {}  
188: options[:html][:type] = ‘button’  
189: options[:html][:onclick] = “#{remote\_function(options)};  
return false;”  
190: options[:html][:name] = name  
191: options[:html][:value] = value  
192:  
193: tag(“input”, options[:html], false)  
194: end

it should be easy to create submit\_to\_remote\_as\_link and change  
“input” on line 193 to “a” and amend related attributes (like :type to  
:href)

just an idea

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [April 21, 2006, 11:08pm UTC](https://www.ruby-forum.com/t/link-to-function-with-submit/58435/3 "2006-04-21T23:08:06Z")

</div>

there is nothing in the link that you can hide with the submit button

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [April 21, 2006, 11:30pm UTC](https://www.ruby-forum.com/t/link-to-function-with-submit/58435/4 "2006-04-21T23:30:36Z")

</div>

Thanx guys.

I will have a look at it.

---

<div class="post-metadata">

**Author:** ![peter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/278dde/32.png) [@peter](https://www.ruby-forum.com/u/peter)\
**Post date:** [April 21, 2006, 10:57pm UTC](https://www.ruby-forum.com/t/link-to-function-with-submit/58435/5 "2006-04-21T22:57:07Z")

</div>

Emin H. wrote:

> Peter, I did not try it myself, but I believe you can create helper  
> similar to the submit\_to\_remote, but creating link instead of button
> 
> looking at the source code
> 
> 184: def submit\_to\_remote(name, value, options = {})  
> 185: options[:with] ||= ‘Form.serialize(this.form)’  
> 186:  
> 187: options[:html] ||= {}  
> 188: options[:html][:type] = ‘button’  
> 189: options[:html][:onclick] = “#{remote\_function(options)};  
> return false;”  
> 190: options[:html][:name] = name  
> 191: options[:html][:value] = value  
> 192:  
> 193: tag(“input”, options[:html], false)  
> 194: end
> 
> it should be easy to create submit\_to\_remote\_as\_link and change  
> “input” on line 193 to “a” and amend related attributes (like :type to  
> :href)
> 
> just an idea

For security reasons you really should use a post to submit the form, a  
link is an exposure.
