Hi,
I am using a multistep form in a Drupal 6 module. The first time I generate the form I get values for form elements , form_id like this:
But when I resubmit the form I get different values for the form element ids :
As you will notice all the elements' ids become 'edit-xxxx-1' to 'edit-xxxx' .
This is causing lot of confusion as I am not able to access the elements using javascript when I need.
Basically this form shows a list from a table. A 'show next' submit button show the next elements - redirects the form to 'step 1' again.
or a 'delete' submit button taking it to next step where the list of entries are deleted.
Is there any way to pass on form-id so that the form elements will have same ids.
Thanks
Karthik
Comments
Sorry the code didn't get displayed
Hi everyone,
Sorry for the double post. But the code didnot display in the previous post..
I am using a multistep form in a Drupal 6 module. The first time I generate the form I get values for form elements , form_id like this:
But when I resubmit the form I get different values for the form element ids :
As you will notice all the elements' ids become 'edit-xxxx-1' to 'edit-xxxx' .
This is causing lot of confusion as I am not able to access the elements using javascript when I need.
Basically this form shows a list from a table. A 'show next' submit button show the next elements - redirects the form to 'step 1' again.
or a 'delete' submit button taking it to next step where the list of entries are deleted.
Is there any way to pass on form-id so that the form elements will have same ids.
Thanks
Karthik
Any resolution
Hi Karthik, did you ever figure out why this was happening.
It currently has me stumped.====
In case anyone happens across this, I might have figured it out. Not sure if my case matches what Karthik was doing, though.
In my case, I have a custom module which produces a form and then via the nodeapi hook, embeds that form into a specific node.
What I discovered was that the "view" hook was being called twice. I really have no idea why it's called twice. But, by adding a
print_r($node)to the above code, I noticed that in the first pass, all form element ID's were in the form of edit-nameofelement and then in the second pass, the ID's changed to edit-nameofelement-1.Again, I'm not sure why that is happening. Maybe some Drupal guru will stumble upon here and drop some knowledge on us.
Anyway, to solve the issue, I utilized the "load" operation to add a new property to the node object which contained the form. Then in the "view" operation, I added the form to the body.
The above code results in a form with ID's that don't have an extra number appended at the end.
Thanks, form_clean_id().
3 years later, and I'm running into this issue when running my form through drupal_execute().
form_clean_id(), which is called in various places through the drupal_*_form() functions, is responsible for incrementing these form ids.
I'm on the hunt for a way to process my form more than one time using drupal_get_form and then drupal_execute...
I'm probably not doing things the right way...
Don't expect this to help anyone at the moment--just leaving some breadcrumbs...
-Steve