Lot of times we come across project requirement where standards form created using contact form or webform is not sufficient or overkill. In this article I am sharing the flexibility of Drupal 8 where I am creating a basic form and rendering the same form into a block

Step 1: Lets create a custom form - Add a file in resume/src/Form/WorkForm.php

Step 2: Now lets display the form we created in step 1 as block. For this create a new file  article/Plugin/Block/ArticleBlock.php


This function should be used instead of self::buildForm() when $form_state is not needed (i.e., when initially rendering the form) and is often used as a menu callback.

Now you can check your page output “Article Block” is displayed in right side on the website.


Source code: https://github.com/xaiwant/D8custom-form-rendring-in-block

Jaywant Topno

Jaywant is associated with Valuebound from past few years. Joined as a Trainee to get engaged with development ops and Drupal Community. Currently he is helping a Content delivery Team to produce a valuable information and newbies to understand Drupal. If you really want to hang around join him on CALL of DUTY, i believe you'll get a perfect head shot.
More about Jaywant Topno

comments powered by Disqus