Drupal: set id attribute in multi-step form

I am creating a multi-stage form in Drupal 6. For some reason, the id attribute of the form element has an additional “-1” when it first displays the form in step 1.

For example, if the form name is "user registration", the first time you access the form in step 1, the id is "user-registration-1". Then, if I go to step 2, id is "user registration". If I go back to step 1, id will remain "user registration".

I would like to know if there is a way to set the id attribute or prevent Drupal from adding extra "-1".

Thanks.

+4
source share
3 answers

You can set the identifier yourself.

 $form['#attributes'] = array('id' => 'user-registration'); 
+4
source

Drupal 6.x has the form API property for the "#id" and "# attribute". I had the same problem, and I found that the #id property was empty, which took into account the empty space in the form field. Then I used the array "#attribute" => ('id' => 'name of id'), which gave me the second "id" in the form field. Remove the id in '#attribute' and add another form API property for '#id'.

 $form['foo'] = array( '#type' => 'textfield', '#title' => t('Foo'), '#required' => FALSE, '#id' => 'text-foo', ); 
+1
source

This worked for me:

 $form = array( '#id' => 'myformid' ); 
0
source

Source: https://habr.com/ru/post/1303417/


All Articles