Skip to content

Form API Reference : Drupal

Marie-Louise edited this page Jan 17, 2019 · 2 revisions

Drupal uses and API to build forms so in order to build them it's necessary to use an array in conjunction with a reference.

so for example in ticket #3326, this is the form which I need to edit (I've added the span tag and aria labels)

   $form['submit'] = [
      '#type' => 'submit',
      '#value' => t('Subscribe'),
      '#prefix' => '<span role="button" aria-pressed="false" tabindex="0">',
      '#suffix' => '</span>'
    ];
    $form['#submit'] = ['corp_newsletter_form_submit'];
  }
  return $form;
}

This is the reference guide:

Drupal Form API

Clone this wiki locally