Display a form in a block or controller drupal
Most often we may want to show our custom forms in blocks. Here are the simple steps to accomplish this.
In the below code we will create a form called “MymoduleExampleForm” and this form will be placed in a custom block called “MymoduleExampleBlock”.
Step 1 – Create a custom module say 'mymodule'. For details on how to create a custom module in Drupal
Step 2 – Create a php file named MymoduleForm.php in mymodule/src/Form and place the following code.