# Soliciting suggestions - Form within a Form

**URL:** <https://www.ruby-forum.com/t/soliciting-suggestions-form-within-a-form/63942>\
**Category:** Rails\
**Created:** [June 20, 2006, 7:34pm UTC](https://www.ruby-forum.com/t/soliciting-suggestions-form-within-a-form/63942 "2006-06-20T19:34:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [June 20, 2006, 7:34pm UTC](https://www.ruby-forum.com/t/soliciting-suggestions-form-within-a-form/63942/1 "2006-06-20T19:34:13Z")

</div>

Greetings!

I could use some suggestions on how to proceed from where I am to where  
I want to go.

I’m working on an app that collects info from the visitor and saves it  
to a file. The file can later be read in for update. To collect the  
info, the app presents a form with a set of checkboxes. The state of  
the checkboxes at initial presentation is controlled by a summary record  
that is created / populated when the file is read in for updating. The  
record contains fields for each of the checkboxes with the value = ‘y’  
or ‘n’. In addition to a set of ‘standard’ selections, the form also  
has a checkbox labeled ‘Other’.

Currently, when the form is submitted, individual records are created  
for each checked checkbox for the standard selections. If the ‘Other’  
checkbox is checked, after records are created for the ‘standard’ items,  
I render a second page with a form that allows them to enter one or more  
other items. Individual records for those items are created via RJS as  
the items are entered.

I’d like to allow the addition of the ‘Other’ items on the same page as  
the standard checkbox selections. If the visitor checks the ‘Other’  
checkbox, I want to replace the checkbox with the partial that’s  
currently being rendered on the second page. I can do that by putting  
the ‘Other’ checkbox in a

 and doing an RJS ‘replace\_html’.

Unfortunately RoR doesn’t support forms within forms. Clicking the  
‘Submit’ button on the sub-form submits the entire form. So that  
doesn’t work for me.

I’m considering eliminating the top level form and just using a  
‘button\_to’ to pass the entered info from the view back to the  
controller.  
Pro: The ‘Other’ form processing works fine  
Con: Since they’re not contained within a form anymore, the checkboxes  
aren’t serialized and passed to the controller via the params hash.

I believe I can use ‘checkbox\_tag’ instead of ‘checkbox’ to get the  
values back to the controller, but that leaves me with the chore of  
initializing them for presentation from the values in the summary  
record. Overall, this path feels non-Railish.

Any suggestions would be greatly appreciated.

Thanks,  
Bill

---

<div class="post-metadata">

**Author:** ![wpwood](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/d6d6ee/32.png) [@wpwood](https://www.ruby-forum.com/u/wpwood)\
**Post date:** [June 22, 2006, 4:39am UTC](https://www.ruby-forum.com/t/soliciting-suggestions-form-within-a-form/63942/2 "2006-06-22T04:39:18Z")

</div>

Bill W. wrote:

> I’m considering eliminating the top level form and just using a  
> ‘button\_to’ to pass the entered info from the view back to the controller.  
> Pro: The ‘Other’ form processing works fine  
> Con: Since they’re not contained within a form anymore, the checkboxes  
> aren’t serialized and passed to the controller via the params hash.

The Rails AJAX helpers have a :submit options that will serialize  
all named inputs within a specified block tag. No form tags required.

–  
We develop, watch us RoR, in numbers too big to ignore.
