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

Render How do I render a form in drupal 8from a controller?

Source Link
Rituraj Kumar
  • 316
  • 1
  • 3
  • 17

Render form in drupal 8

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.