Hey I have searched around and not really found a clear answer to how this would work, if someone can point me in the right direction that would be most swell.

I have a form that has 4 steps to it, on the last step I have 4 textfields gathering creditor information. I would like to have a link that will duplicate those 4 inputs so you can add another creditor, and another, and another.

At first I just used Ajax, but when submitting the form it didn't notice the new elements. I found some discussions on the poll.module, and realize that I have to re-build the form with the new elements.

I guess I'm just not really clear on how to do that step, I tried to copy the code and tweak it for my form but the button just spins and nothing happens.

So either I'm tweaking it wrong, or it's because I'm trying to do it to the 4th step of a multi-step form and that adds complication that I am not as of yet fully aware.

SO I figured I'd give asking a try.
- Jordan

Comments

buermann’s picture

Nevermind, figured it out.

glennnz’s picture

buermann

How did you get Ajax to add the new fields to your form, and then submit them?

Thanks

Glenn

Glenn
THECA Group

svogel’s picture

Hi buermann,

I would be interested, too.
Do you mind posting your results?

Thanks a lot
Stefan

jaypan’s picture

Just adding the form elements through ajax doesn't work. When Drupal creates a form, it uses drupal_get_form(). This function creates a cached version of the form on the server, and then sends the HTML version of the form to the user. After the user submits the form, Drupal compares the cached version of the form with the version on the server, and anything that exists in the HTML version that doesn't exist in the cached version is ignored. This is done for security purposes, so that people can't hack your forms.

The way around this is to use AHAH - a subset of AJAX that has a bunch of Drupal functions built in. The advantage - it works, and you don't need to know any javascript whatsoever to build this, as Drupal already has preexisting PHP script that write the JavaScript for you. The disadvantage - AHAH is EXTREMELY hard to implement in Drupal. It's probably the most difficult thing I've come across. But, using the AHAH Helper module makes things a hell of a lot easier, so you can try that.

But I would suggest spending some time learning how to build multistep forms in Drupal before working with AHAH and the AHAH helper module. AHAH enabled forms work essentially like a multistep form, only they don't require a page refresh. But the form script itself is written the same, so a strong understanding of multi-step forms is imperative first.

Contact me to contract me for D7 -> D10/11 migrations.

francewhoa’s picture

The module Multistep is able to do that http://drupal.org/project/multistep

Loving back your Drupal community result in multiple benefits for you