By ponkarthik on
I am using a multistep form in Drupal 6.x. But in each step or even in same step on resubmissions I get different form ids and different element ids.
The first time I get something like 'edit-xxx-1' but subsequent times I get 'edit-xxx' without the number. Because of this I am not able to access the form elements with javascript, jscript as I need same element id .
Is there a way to pass on the form id to subsequent requests ?
Karthik
eg.
<input type="text" maxlength="10" name="end_date" id="edit-end-date-1" size="10" value="01/01/2030" class="form-text" />
<input type="submit" name="op" id="edit-submit-1" value="Delete" class="form-submit" />
<input type="hidden" name="form_build_id" id="form-47126414ffa9ca562649c147be56f8d5" value="form-47126414ffa9ca562649c147be56f8d5" />
<input type="hidden" name="form_token" id="edit-alogbook-formz-form-token-1" value="73eed4b9915bdc16f86cbb497c41b48b" />
<input type="hidden" name="form_id" id="edit-alogbook-formz-1" value="alogbook_formz" />
But when I resubmit the form I get different values for the form element ids :
<input type="text" maxlength="10" name="end_date" id="edit-end-date" size="10" value="01/01/2030" class="form-text" />
<input type="hidden" name="form_build_id" id="form-6149df05f231c641a14ed5e91055c9a2" value="form-6149df05f231c641a14ed5e91055c9a2" />
<input type="hidden" name="form_token" id="edit-alogbook-formz-form-token" value="73eed4b9915bdc16f86cbb497c41b48b" />
<input type="hidden" name="form_id" id="edit-alogbook-formz" value="alogbook_formz" />
<input type="submit" name="op" id="edit-submit" value="Delete" class="form-submit" />
Comments
Better late than never
Well, I'm going to suggest the best way is with your own module code.
Then I think the best thing to do is give your element a class, (for argument sake, 'my-element'), with a hook_form(), or hook_form_alter() depending on your use case like one of these:
my_module.module in function hook_form:
or my_module.module in function hook_form_alter:
my_module.js
In the worst case, if none of the above would work for you (or maybe the js / behaviors scare you) you could simply override your element's default 'id' using the '#id' FAPI element, I did this before I was comfortable with Drupal behaviors when my javascript had to grab a specific element.
Good luck