Using a link to submit a form

I have a list of items. each item will have a checkbox next to it. I
have a series of commands (in a sidebar div) that should perform an
operation on the selected items in the list.

I know how to encapsulate that list with a form and then perform the
operations on the checked items, but my question is, how do you (and
can you) gather up the checked items on the click of the link and
submit them to a controller for processing?

This may not be much help, but you can pass multiple arguments by using
the link helper (or any helper for that matter):

<%= link_to ‘Submit’, :action => ‘my_action’, :id => @user.id, :name =>
@user.name %>

But I don’t know how to do this using checkboxes or text fields that are
not wrapped in form tags. You might try passing the value of the id that
you gave to your checkboxes and then in your method that is called by
the :action if they are checked or not.

Shandy N. wrote:

But I don’t know how to do this using checkboxes or text fields that are
not wrapped in form tags. You might try passing the value of the id that
you gave to your checkboxes and then in your method that is called by
the :action if they are checked or not.

This is a neat trick: (ajax-version)

link_to_remote(‘submit’, :url => {:action => ‘blabla’, :id =>
‘optional’}, :submit => “id_of_element_around_your_checkboxes”)

The important part is the :submit option ofcourse, just wrap the
elements you want to submit in a

(or whatever) and everything in
it will be posted as if it was in a form.
Very usefull for posting rows of a table, because you can’t put a form
around a complete row. Or for posting something that’s inside a form
(forms in forms are not allowed)

Regards,

Stijn

Sounds like a great solution. I will try it, thanks!

On 7/19/07, Stijn P. [email protected] wrote:

link_to_remote(‘submit’, :url => {:action => ‘blabla’, :id =>
‘optional’}, :submit => “id_of_element_around_your_checkboxes”)

The important part is the :submit option ofcourse, just wrap the
elements you want to submit in a

(or whatever) and everything in
it will be posted as if it was in a form.
Very usefull for posting rows of a table, because you can’t put a form
around a complete row. Or for posting something that’s inside a form
(forms in forms are not allowed)

that is a great tip, Stijn! A shame I didn’t see your message
yesterday, I
really could’ve used it! Was trying to submit a form using
link_to_remote
and :with => Form.serialize(…) but I kept running into difficulty…
This
works perfectly, thanks!

Adam

Stijn P. wrote:

Shandy N. wrote:

But I don’t know how to do this using checkboxes or text fields that are
not wrapped in form tags. You might try passing the value of the id that
you gave to your checkboxes and then in your method that is called by
the :action if they are checked or not.

This is a neat trick: (ajax-version)

link_to_remote(‘submit’, :url => {:action => ‘blabla’, :id =>
‘optional’}, :submit => “id_of_element_around_your_checkboxes”)

The important part is the :submit option ofcourse, just wrap the
elements you want to submit in a

(or whatever) and everything in
it will be posted as if it was in a form.
Very usefull for posting rows of a table, because you can’t put a form
around a complete row. Or for posting something that’s inside a form
(forms in forms are not allowed)

Regards,

Stijn

Hey, where were you about 2 1/2 weeks ago? I got to admit, this sounds
like a really good idea. I might have to go back and change things in my
forms. Thanks Stijn

~S