Sending form data with link_to_remote


#1

I have a form with several text_fields that is submitted with a standard
“submit” button.

With one of the text_fields, however, I’d like to have a “Test This”
link next to it that will submit the text field entry and perform a
simple test at the server. The server will then respond with some RJS
to indicate pass/fail status.

I can use “observe_field” to do this automatically on the field data,
but I’d rather have a separate link to do this.

Since this is part of a bigger form, I don’t think I can use another
form_remote nested within.

Is there a handy way to create such a thing?


#2

Jake J. wrote:

Since this is part of a bigger form, I don’t think I can use another
form_remote nested within.

That might be the notorious ‘with FAQ’, which I myself have asked.

Send the link_to_remote using :with => ‘Form.serialize(“my_form”)’,
IIRC.

That converts the form’s current values into GET parameters.


Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!


#3

On 15-Feb-07, at 1:18 PM, Phlip wrote:

RJS
Send the link_to_remote using :with => ‘Form.serialize(“my_form”)’,
IIRC.

That converts the form’s current values into GET parameters.

or if you don’t want to sent the entire serialized form, you can use
the following js method:

function serialize_form_elements(form_elements_array) {
var queryComponents = new Array();

for (var i = 0; i < form_elements_array.length; i++) {
var queryComponent = Form.Element.serialize(form_elements_array
[i]);
if (queryComponent)
queryComponents.push(queryComponent);
}
return(queryComponents.join(’&’));
}

usage:

get_query_string = serialize_form_elements([$('form_element_1'), $

(‘form_element_2’)); #you can probably just pass an array of element
id’s

and then plug that into like_to_remote with ‘:with’ as Phillip said.

note: relies upon prototype’s Form.Element.serialize smarts.

Cheers,
Jodi
General Partner
The nNovation Group inc.
www.nnovation.ca/blog


#4

On 15-Feb-07, at 1:32 PM, Jake J. wrote:

Thanks, Jodi, Philip–

I was having some trouble with some code I found. I’m using this:

:with => “‘bucket=’+$(‘crummy’).value”

and it seems to work just peachy!

that’ll work just find until you try that trick with checkboxes,
radiobuttons, selects. That’s when you want to serialize

Cheers,
Jodi
General Partner
The nNovation Group inc.
www.nnovation.ca/blog


#5

Thanks, Jodi, Philip–

I was having some trouble with some code I found. I’m using this:

:with => “‘bucket=’+$(‘crummy’).value”

and it seems to work just peachy!

Cheers,
Jake


#6

Jodi S. wrote:

:with => “‘bucket=’+$(‘crummy’).value”

and it seems to work just peachy!

that’ll work just find until you try that trick with checkboxes,
radiobuttons, selects. That’s when you want to serialize

Thanks! The only reason I could think not to do that is a general
reticence against deeply nested inescapable quotes and delimiters. As
a rule of thumb…

And I think Form.serialize calls a Form.Element.serialize, or
something, that’s accessible…


Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!