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()-&gt;getForm('\Drupal\modulename\Form\fp');

return [

  '#type' =&gt; 'markup',

  '#markup' =&gt; $form,

];


}

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

but showing
Form Title Array

how to render form.
First of all why use a _controller if all you need to do is print a form? Instead it should have _form something like this: Drupal\example\Form\DefaultForm in the routing definition.

Here is a simple guide on how to create a form in drupal 8 https://www.valuebound.com/resources/blog/step-by-step-method-to-create-a-custom-form-in-drupal-8

And if you really want to embed a form in a controller response check this out How do I embed a form in a controller response?