Posting input feilds using link

I have a page that contains a form and some input fields. instead of a
submit button to post the data back to the server I want to put a link.
This link when clicked should post the data back to the server. Any
pointers on how to do this? I have put a link, but it doesn’t post back
the data from input elements, i also set :post => true in link_to URL
helper but its not working. Please help

Dipesh B. wrote:

I have a page that contains a form and some input fields. instead of a
submit button to post the data back to the server I want to put a link.
This link when clicked should post the data back to the server. Any
pointers on how to do this? I have put a link, but it doesn’t post back
the data from input elements, i also set :post => true in link_to URL
helper but its not working. Please help

I think you still want to submit the form using a post, but you want a
link to do it instead of a button?

In that case, you should still be using a form tag set up with the
correct action and parameters. Then create a link to submit the form.
But we’ll use JavaScript to submit it, so we can’t really use link_to.
We’ll use link_to_function instead.

link_to_function “Link Text”, “document.forms[0].submit();”

This will submit the first form on the document (the page). If you have
more than one form on the page, you’ll have to specify which one.

On Oct 13, 2006, at 18:32, Dipesh B. wrote:

I have a page that contains a form and some input fields. instead
of a submit button to post the data back to the server I want to
put a link.
This link when clicked should post the data back to the server. Any
pointers on how to do this?

You need to create a link that executes some javascript which submits
the form when clicked. $(‘id_of_form’).submit() or something to that
effect is the Javascript you want.


Jakob S. - http://mentalized.net

Kian Wright wrote:

I think you still want to submit the form using a post, but you want a
link to do it instead of a button?

In that case, you should still be using a form tag set up with the
correct action and parameters. Then create a link to submit the form.
But we’ll use JavaScript to submit it, so we can’t really use link_to.
We’ll use link_to_function instead.

link_to_function “Link Text”, “document.forms[0].submit();”

This will submit the first form on the document (the page). If you have
more than one form on the page, you’ll have to specify which one.

I tried to do this too (taking your suggestion above), but when I make a
change on the form and click my “Save” link_to_function, I get an
endless “Loading…” and have to restart the server to move anywhere.
What did I do wrong? I tried it with and without a semi-colon. I only
have one form on the page, the one that Rails creates from the
start_form_tag, which happens to be lower on the page that the “Save”
link (but the position shouldn’t matter, right?).

Shauna

Shauna wrote:

I tried to do this too (taking your suggestion above), but when I make a
change on the form and click my “Save” link_to_function, I get an
endless “Loading…” and have to restart the server to move anywhere.
What did I do wrong? I tried it with and without a semi-colon. I only
have one form on the page, the one that Rails creates from the
start_form_tag, which happens to be lower on the page that the “Save”
link (but the position shouldn’t matter, right?).

Shauna
Check again the form
I tried
link_to_function “Link Text”, “document.forms[0].submit();” too and my
start_form_tag working properly