W3cubDocs

/Drupal 8

public function FormBuilderInterface::buildForm

public FormBuilderInterface::buildForm($form_id, FormStateInterface &$form_state)

Builds and processes a form for a given form ID.

The form may also be retrieved from the cache if the form was built in a previous page load. The form is then passed on for processing, validation, and submission if there is proper input.

Parameters

\Drupal\Core\Form\FormInterface|string $form_id: The value must be one of the following:

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The rendered form. This function may also perform a redirect and hence may not return at all depending upon the $form_state flags that were set.

Throws

\Drupal\Core\Form\FormAjaxException Thrown when a form is triggered via an AJAX submission. It will be handled by \Drupal\Core\Form\EventSubscriber\FormAjaxSubscriber.

\Drupal\Core\Form\EnforcedResponseException Thrown when a form builder returns a response directly, usually a \Symfony\Component\HttpFoundation\RedirectResponse. It will be handled by \Drupal\Core\EventSubscriber\EnforcedFormResponseSubscriber.

See also

self::redirectForm()

File

core/lib/Drupal/Core/Form/FormBuilderInterface.php, line 92

Class

FormBuilderInterface
Provides an interface for form building and processing.

Namespace

Drupal\Core\Form

Code

public function buildForm($form_id, FormStateInterface &$form_state);

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Form!FormBuilderInterface.php/function/FormBuilderInterface::buildForm/8.1.x