Hey all,

I have an interesting problem, would like to use Webforms but will use Form API if necessary.

Essentially, I have a multipage form.
1). On page 1, I have a textbox. I need a (+) button that if clicked, will add a second field of the same type (up to 5).
2). On page 2, I want to get the data that was input from page 1, and output it on page 2 in the form of a checkbox.

Example:

Page 1 - I enter : Bob, hit (+) get a second input box and in it I enter Sandy. Click "next" to go to page 2.
Page 2 - Two unset checkboxes appear (dynamically created based on input from page1), the first with a label Bob, the second labeled Sandy.

Is this possible?

Comments

bsenftner’s picture

What you're tying to do is not too difficult, with Form API and a little bit of java script.

First, create the entire form with all 5 textboxes, but give them CSS classes so they can be modified by this java script:

http://www.missingubercartmanual.com/The-Basics-of-using-Java-Script-in-...

With that script, you can create form elements that are hidden, and when another element is clicked they appear.
I suggest you create a nested series of 5 such hidden elements, with the '+' sign un-nesting the elements.
Of course, each element is one of your textboxes and the + sign to reveal the next one.

That's how to handle the first page of your two page form. The second page is handled via normal form API, but with logic that checks to see which page-one form elements had data in them and use only those fields for your final checkboxes form.

You may also want to check out the Ctools setup for multi-page forms:
http://www.nicklewis.org/using-chaos-tools-form-wizard-build-multistep-f...
But I'm not sure if it would handle your dynamic second page. (haven't really looked that hard.)
Ctools is compatible with that java script though.