Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Creating custom form in drupal 8

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 6
    • 0
    • 3.43k
    Comment on it

    Drupal 8 and Drupal 7 basically have similar API with slight difference. In Drupal 7 form uses the array structure for rendering the data but it has the separate submission and validation function. In Drupal 8 comes with a feature that we can use the html 5 elements like  'date','url','range','number','search', 'email', 'tel' etc.

     

    While making forms in drupal 8 we basically make different function. like buildForm for building the form in this function we make the inputbox,  selectbox, checkbox.

     

    File structure goes like this:

     

     

    To make the custom module you have to follow these steps.

     

    Step 1: The first step in creating custom form is to make info.yml file. In that file you have to mention name, package you are using, dependencies etc.

     

     

    Step 2: Next step is make routing.yml file in that file we basically give the path of that file, permission that who will have access to those content.

     

     

    Step 3: Next step is to make the form ResumeForm.php file in that file we make various function first function we make is to get the form id. Second function we make is to build the form. In the third function we validate the form and the last function we make is to submit the form.

     

     

     

    Step 4: Then you have to go to Manage->Extend. In the extend section you have to go the search bar then you have to search for your form that you have created after that you have to install that. Now your form is ready to work. 

     

    Now only thing you have to  do is to make give the url. Like mine is localhost/stonesdrupal/resume/myform. This is how the form looks like.

     

    Result:

     

     

     

     

     

     

    Creating custom form in drupal 8

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: