Topic: form.serialize with a text submit on a form instead of a button

I have a form that I currently have working with a button, but it would look much better using a textlink. It using partials to update the favorite player. Here's the code I have:

<% form_remote_tag :url => {:action => :add_to_favoriteplayer, :controller => 'favoriteplayer' } do %>
    <%= hidden_field 'favoriteplayer', 'user_id', :value => current_user.id %>
    <%= hidden_field 'favoriteplayer', 'player_id', :value => @player.id %>
   
    <%= link_to_remote "Add to Favorites", :url => {:action => 'add_to_favoriteplayer', :controller => 'favoriteplayer', :method => 'post', :with => "Form.serialize(this)+'&='"}%>
    <% end %>

Can anyone help me figure out how to do this? As I said it works with the button, but not with this link, I found a blog that said to add +'&=' to make it work but no go.

Any ideas?

Thanks in advance!

Don

Re: form.serialize with a text submit on a form instead of a button

If anyone can figure this one out I'd still appreciate it, but what I wound up doing was setting a class for the submit button and then using CSS to alter it's look to make it look more like a text link with this CSS:

font-weight: bolder;
color: #FF1A00;
text-decoration:underline;
background-color: #FFFFFF;
border-width: 0;
cursor: pointer;
width: 250px;
padding-top: 0px;
margin: 0;

Hope that helps someone, and if anyone can figure out how to do the form.serialize I would still appreciate it!

Don

Re: form.serialize with a text submit on a form instead of a button

Try using

<%= link_to_remote "Add to Favorites", :url => {:action => 'add_to_favoriteplayer', :controller => 'favoriteplayer'},:submit=>'your_form_id'

Re: form.serialize with a text submit on a form instead of a button

Dang railsforum,

I have been searching for the answer to this question for a long time. This is great! But how about using Form.serialize with a link_to? Anyone know anything about that?

Re: form.serialize with a text submit on a form instead of a button

So you dont want an AJAX call?

I'm guessing here, but try looking at the :method => :put or :method => :delete options for link_to.  I think in this case the form is automatically serialsed...

More here: http://ryandaigle.com/articles/2006/05/ … nk-helpers

Re: form.serialize with a text submit on a form instead of a button

Excellent response time, Thanks...

Yes, that is correct. I want a link (non-ajax) that posts a serialized form. I am unclear on how to specify the id of the form I want to serialize and post with the request.

Rails API, link_to
...method => symbol of HTTP verb: This modifier will dynamically create an HTML form and immediately submit the form for processing using the HTTP verb specified....

Can you specify an existing form id when using the :method option in a link_to helper?

Re: form.serialize with a text submit on a form instead of a button

I suspect all forms will be serialised.

Do you have more than one form on your page?  If so, are the field names unique across forms?  If yes the than should work (access the params hash as usual).

Re: form.serialize with a text submit on a form instead of a button

When I use the :method option in a link_to, it creates a blank form. This form is passed the link_to url and posts the request with the help of the blank form. So I never get the option to tell the link_to anything to serialize. But, let me explain what I am trying to accomplish...

I have a form with a submit button at the bottom. Users can submit the form and it processes fine. Next to the submit button, I have a preview link. So I want  to give the user the ability to click the preview link and send the serialized form data to a preview action to preview it.

So... If I am using the wrong approach here, please let me know!

(yes, I know the topic of this thread is no longer the topic of this post... but the ideas are related...)

Re: form.serialize with a text submit on a form instead of a button

Reposted in Application Theory & Strategy, sorry I tainted the AJAX and RJS topic!