Skip to main content

Form API

knackforge blog knowledge base

Drupal form's #tree option

There may be a need to name the form elements in an array structure how the form is built. You can see this in Ubercart checkout pane form's input elements. This is very useful when one has a large multi-part form which can be grouped easily by their POST content's array format.

Eg: panes[delivery][delivery_first_name]

A simple flag on you $form construct array will do the trick. It's the #tree option. For whichever elements you set this #tree option, the element's children will be named with full reference to its parents.

Dynamic form fields

Create Dynamic Form Fields in Drupal 7

Drupal's Form API helps developers to build complex, extensible forms with minimal code and also gives the option to make the form fields as dynamic. It means to change/create form fields based on the other field's given value. There is a cool trick to make dynamic fields in drupal.

Clearing textfield in drupal

Adding a clear button to Drupal form API text field

We wanted to have a quick clear button for any text field (similar to address bar of browsers in mobile and tablet devices). Snapshot below might explain it much better. In this you are seeing email search field in newsletter filter form.

While I was in search for creating this, I found HTML5 is as the way to go. One can simply create that by using "search" input type. The proper HTML tag for the same is below,

bootstrap  form tabs

Creating horizontal form tabs in Drupal 7

Creating Vertical tabs in Drupal 7 forms is an easy task, but to accommodate the design needs we at times have to use different style. For instance, horizontal tab might be needed. The same makes more sense for shopping cart check out like pages. And here the need for looking solutions outside the Drupal core arises as horizontal tabs are not readily available in core.

knackforge blog knowledge base

Drupal Form API - Overriding required field asterisk

Forms are the essential components of Dynamic websites. At KnackForge we firmly believe and make the best use of Drupal CMF. API forms the backbone of Drupal's success and Form API is the most important among them. When Form API used together with the blend of themeing layer, it gives a fine control to get the desired output.

Forms in Drupal are created using PHP array.

Subscribe to Form API