You Should Invest In Forms
In a digital marketing, Most of the customer requirement is gathered through forms. So its
essential to spend some time with forms
Example : a user can search a particular product using the search form on an e-commerce website.
Form API in Drupal 8
As we know already Drupal use forms for most of the administrative site building.
Drupal 8 follows object-oriented style of programming with the integration of symfony .
Based on the purpose of the form, it can inherit the basic properties and methods of the below classes.
1.Config Base
2.FormBase
3.ConfirmBase
Note: Routing configuration is done through the yml files in drupal 8
When the user hits the valid url in the browser , Major Responses are
1.Page Content
2.Forms
3.Map..etc.
Basic Routing Configuration for Form
Internal path-machine-name
Path: url of the path
Default
Form:Name of the Form class with the name space
requirements:
_permission: 'access content'
Example:
user.multiple_cancel_confirm:
path: '/admin/people/cancel'
defaults:
_form: '\Drupal\user\Form\UserMultipleCancelConfirm'
_title: 'Cancel user'
requirements:
_permission: 'administer users'
To know more about routing options Check this Link Routing In Drupal 8
In this Post we will examine Basic Form
Namespace
namespace is like a pointer to a file path where you can find the source of the function you are working with.
Use statement
The ability to refer to an external fully qualified name with an alias, or importing, using the use operator
FormBase , FormStateInterface are the two classes which defines most of the basic
properties of any form . So it is essential to extend your form with FormBase Class
1.BuildForm - is a function which is defined in formbase class, it is mainly used to describe the form elements
2.getFormId - It returns the form id
3.validateForm - This function is used to perform some of the server side validation before submitting to the server or database
4.submitForm - Its is used to retrieve the submitted values and made the other logics with the submitted dat
Here i have covered very basic example and explanation . Follow the drupal org documentaion to more information.
Comments