form

Create a custom form field for entity reference with auto complete in Drupal 8.

The Entity reference module provides a auto complete field widget and this has been changed to a Form API element as 'entity_autocomplete'. This can be used in normal custom forms. Form element type can be used as 'entity_autocomplete' for entity reference fields. Following is a sample code structure to create a entity reference fields with in custom form.

Drupal 7: CTools adding CSS to Modal window with example[ctools_add_css()]

In Drupal core the function drupal_add_css() help us to achieve adding CSS for a specific pages. The CTools modal popup will not support core drupal_add_css() functions. We have to use CTools functions for adding CSS files to modal window. The function ctools_add_css() will help to adding CSS files into modal popup windows. The function accepts filename, Module name and path for adding the CSS file.

Drupal 7: CTools adding JS to Modal window with example[ctools_add_js()]

In Drupal core the function drupal_add_js() help us to achieve adding JS for a specific pages. The CTools modal popup will not support core drupal_add_js() functions. We have to use CTools functions for adding JS files to modal window. The function ctools_add_js() will help to adding JS files into modal popup windows. The function accepts filename, Module name and path for adding the JS file.

Drupal 7: Render Drupal system forms in custom module[drupal_get_form()]

The function drupal_get_form() is used to get the form details. Normally in Drupa,l the form field are constructed as an associative array. This associative array is defined inside a form function. The function name is the form ID, using this form ID we can able to render the form.

Drupal 8: Programatically create Add another field - Example

In Drupal for form fields we able to capture multiple values by specifying unlimited values in manage fields. A similar manner for custom fields added in form alters also able to capture multiple values. The below is the example of creating multiple value capture field with add another button.

Drupal 8: Adding custom CSS to form or page

The Drupal we can able to add custom CSS files to our forms. In Drupal 8 adding custom, CSS files will be achieved by using the library to system. The library files are needed before adding to form. These libraries descriptions are added in MODULE_NAME.libraries.yml files. Once libraries added we can able to define in our forms.

Drupal Inline Entity Form Module hook_form_alter()

The Inline entity form is the Drupal Contribute module. Which help to embed a entity form into another entity. Example: Commerce product add form cam be used in Node form. This module will help to create, update and delete entity based on its parent entity. This module embed entity form as the object to its parent form. To alter this specific entity form there is hook called hook_inline_entity_form_entity_form_alter(). Below is the syntax and example to usage of hook_inline_entity_form_entity_form_alter() to alter inline forms.

Drupal 7 : Hiding Form Field groups with samplecode

For Drupal forms we can add Field Groups. These field groups are commonly HTML element, Div, HTML5, Fieldset, Vertical tabs group, Vertical tab, Horizontal tabs group, Horizontal tab, Multipage group, Multipage, Accordion group, Accordion item, Multiple fields container, Multiple fields table and Multiple fields as label-value. We can able to hide Field Groups in Form alter by different methods. Below are some types to hide the Field Groups.

Drupal 8 : Webform alter change fields labels, hiding fields, custom validate and submit with example

In Drupal we can alter a form using the HOOK, hook_form_alter(). Webforms are used to create forms in interfaces. We can alter webform using hook_form_alter to change field types, label and custom validate or submit for our purposes. The below example will show editing the webform fields and adding custom validate.

Drupal 8 : Custom Form Validate and Submit in hook_form_alter() with Example

In Drupal 8 we can able to call custom validate and submit function for our need. This custom functions need to be defined in hook_form_alter(). Validate is defined as array parameter for #validate key of $form array. Similarly for submit is defined as array parameter for #submit on $form submit action.