Forum: Ruby on Rails link_to_function with submit

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peter (Guest)
on 2006-04-21 19:23
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
Emin H. (Guest)
on 2006-04-21 21:41
(Received via mailing list)
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
James M. (Guest)
on 2006-04-22 00:57
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.
Emin H. (Guest)
on 2006-04-22 01:08
(Received via mailing list)
there is nothing in the link that you can hide with the submit button
Peter (Guest)
on 2006-04-22 01:30
Thanx guys.

I will have a look at it.
This topic is locked and can not be replied to.