Hello,
So I have a form where the user clicks "add another row" and it adds like one or two more text fields each time this is clicked.

I can get it to work properly using $form_state['rebuild'] = TRUE; . However, it refreshes every time, so each time the user clicks the button the fields become empty and it also doesn't work with required => TRUE.

Is there a way to use jQuery or AHAH to add new text fields dynamically, and let the validation/submit handler know that these new fields exist dynamically (perhaps a simple loop to check how many of these rows there are without using any AJAX)????

http://drupal.org/node/331941 this describes how to add new stuff via AHAH, but would it fit the description of what I want to do? Or is it unnecessary since I can maybe just add a line of jQuery or PHP to do what I want without any AJAX calls.

Thanks.

Comments

jaypan’s picture

You need AHAH to be able to do this. *Unless* you load the fields on page load and hide them, showing them dynamically. But anytime you want to create new fields that didn't exist when the form was generated, you need AHAH.

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

executex’s picture

Yes, I thought so. Thanks. AHAH is necessary for it. I was just wondering if there was a simpler AJAX method as AHAH looked a bit complicated at first glance.

The only problem I have now is, I'm trying to use the cool Compact Forms module, but when you add new elements dynamically, those don't have the cool javascript on them.