Reputation: 8289
I'm building a multi-step form in Drupal 6. For some reason, the id
attribute of the form
element have an extra "-1" the first time the step 1 form is displayed.
For example, if the form name is "user-registration", the first time I access the step 1 form, the id
is "user-registration-1". Then, if I go to step 2, the id
is "user-registration". If I go back to step 1, the id
remains "user-registration".
I'd like to know if there's a way for me to set the id
attribute or to prevent Drupal from adding the extra "-1".
Thanks.
Upvotes: 5
Views: 6076
Reputation: 11
Drupal 6.x has a form API property for both '#id' an '#attribute'. I had the same problem and found that the '#id' property was blank, which accounted for the blank 'id' in the form field. Then I used '#attribute' => array('id' => 'name of id'), which gave me a second 'id' in the form field. Remove the id in the '#attribute' and add another form API property for '#id'.
$form['foo'] = array(
'#type' => 'textfield',
'#title' => t('Foo'),
'#required' => FALSE,
'#id' => 'text-foo',
);
Upvotes: 1
Reputation: 33275
You can set the id yourself.
$form['#attributes'] = array('id' => 'user-registration');
Upvotes: 4