
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 8 See here
Step 2 – Create a php file named MymoduleExampleForm.php in mymodule/src/Form and place the following code.