May 17, 2007
Passing an entire form with a HTML hyperlink
In one of my projects I came across a situation where I needed to submit a form with a link. By default, a form is submitted either using a submit_tag or button_to helpers in ruby on rails. In this case it had to be submitted through a link. For this, I searched and found a way to do it:
<%= link_to_remote 'Submit', :url => {:controller => 'c_name', :action => 'a_name', :id => 'some_id'}, :with => "Form.Element.serialize('form_id')" %>
Alternatively, you can also use the following helper:
<%= link_to_function 'Submit', remote_function(:url => {:controller => 'c_name', :action => 'a_name', :id=>'some_id'}, :method => :post, :with => "Form.serialize('form_id')") %>
The form can be passed using the optional paramter :with.
One Comment, Comment or Ping
Dave
Thanks for this! I had to serialize the whole form but changing it slightly (removing “.Elements”) worked:
{ :controller => “controller”, :action => “action”},
:loading => “[whatever]“,
:success => “[whatever",
:complete => "[whatever]“, :with=>”Form.serialize(’form_id”} %>
{:id => “form_id”} do |form| -%>
Dec 11th, 2007
Reply to “Passing an entire form with a HTML hyperlink”