Skip to main content
2 of 2
removed "Drupal" and tags from the title
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

How do I render a form from a controller?

Render form in Drupal 8.

In modulename.routing.yml

modulename.fp:

path: '/formpage'

defaults:

_controller: '\Drupal\modulename\Controller\*Controller::formpage'

Write code in controller.php

public function formpage() {

$form = '';

$form = 'Form Title';

$form .= \Drupal::formBuilder()->getForm('\Drupal\modulename\Form\fp');

return [

  '#type' => 'markup',

  '#markup' => $form,

];

}

and write form code in modules\modulename\src\Form\fp.php.

but showing Form Title Array

how to render form.

Rituraj Kumar
  • 316
  • 1
  • 3
  • 17