# Sending form data with link\_to\_remote

**URL:** <https://www.ruby-forum.com/t/sending-form-data-with-link-to-remote/85712>\
**Category:** Rails\
**Created:** [February 15, 2007, 7:06pm UTC](https://www.ruby-forum.com/t/sending-form-data-with-link-to-remote/85712 "2007-02-15T19:06:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [February 15, 2007, 7:06pm UTC](https://www.ruby-forum.com/t/sending-form-data-with-link-to-remote/85712/1 "2007-02-15T19:06:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [February 15, 2007, 7:19pm UTC](https://www.ruby-forum.com/t/sending-form-data-with-link-to-remote/85712/2 "2007-02-15T19:19:47Z")

</div>

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](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [February 15, 2007, 7:29pm UTC](https://www.ruby-forum.com/t/sending-form-data-with-link-to-remote/85712/3 "2007-02-15T19:29:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [February 15, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/sending-form-data-with-link-to-remote/85712/4 "2007-02-15T19:38:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [February 15, 2007, 7:32pm UTC](https://www.ruby-forum.com/t/sending-form-data-with-link-to-remote/85712/5 "2007-02-15T19:32:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![janovetz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@janovetz](https://www.ruby-forum.com/u/janovetz)\
**Post date:** [February 15, 2007, 7:48pm UTC](https://www.ruby-forum.com/t/sending-form-data-with-link-to-remote/85712/6 "2007-02-15T19:48:54Z")

</div>

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](http://c2.com/cgi/wiki?ZeekLand) ← NOT a blog!!
