The Drupal Forms API provides developers with complete control over how forms work within Drupal. By using the Forms API even complex tasks such as working with AJAX are made simple. The Forms API varies a bit between major versions of Drupal but the principles remain the same, take a look at what we've blogged about Forms over the years below...

Read some of our articles about Drupal forms
Article
Posted on 13th January 2025
Takes about 3 mins to read
Fighting spam is an ongoing arms race. There will always be nefarious attempts to post unwanted content onto websites, that's just the nature of the global internet nowadays, but can we keep ahead of it? Some techniques are complex, maybe using AI / natural language processing, but there are also quite simple opportunities to reject spam. We had a lot of contact requests come into our site that used the Cyrillic script - which is...
Article
Posted on 2nd October 2024
Takes about 4 mins to read

Drupal's form API has been brilliant for many years. Still, recently I found myself wondering why I needed to build a configuration form if I already had a schema for my config. Defining a schema facilitates API-first validation (including some pretty smart constraints), specific typing (e.g. actual booleans or integers instead of '0' or '1' strings), and even translation in Drupal. That last part got me thinking; if Drupal automatically provides translation forms for typed...

Article
Posted on 11th March 2024
Takes about 3 mins to read

I recently produced the first release of the Webform Protected Downloads module that is compatible with Drupal 10. It provides the ability for sites to have 'gated' content which users can download once they have filled out a form for their details. This can convert engaged visitors into leads, set up licenses for customers, or simply validate a user for access to a file. Put simply, as the project's description says, this module could be...

Article
Posted on 14th July 2020
Takes about 4 mins to read
This article is part of the series
CM Drupal Contribution Challenge 2020
I recently released a new contributed module to aid translation on Drupal 7 sites: Entity Translation: Separated Shared Elements Form (ETSSEF). Yes, it has a convoluted name! It finally resolves a suggestion from years ago in an Entity Translation project issue, to allow editing untranslatable fields separately to translatable ones. One of our clients has a multilingual product database site with a few hundred fields on their content, so anything like this that could reduce...
Article
Posted on 26th June 2018
Takes about 2 mins to read

Let's say you've built a custom form for your Drupal 8 site. It contains various elements for input (name, email address, a message, that kind of thing), and you want to send the submitted values in an email to someone (perhaps a site admin). That's a pretty common thing to need to do. This could be done with Drupal's core contact forms, webforms, or similar -- but there are cases when a bespoke form is...

Published in: #Drupal Planet #email #Forms #token #Drupal 8
Article
Posted on 17th January 2017
Takes about 2 mins to read

I've previously written about dynamic forms in Drupal, using #states to show or hide input boxes depending on other inputs. Since then, Drupal 7 and 8 have both got the ability to combine conditions with OR and XOR operators. This makes it possible to apply changes when a form element's value does not equal something, which is not obvious at all.

Article
Posted on 5th July 2011
Takes about 2 mins to read

Here's a quick follow-up to my original post on Dynamic forms in Drupal 7, as a reply to Wappie08, who asked me about combining conditions in the #states array to add increased control over the display of your form elements. The question: Hi James Williams, I read your blog post about d7 & #states in the FAPI which is really cool! One problem is that the information is also listed in the drupal.org example module...

Article
Posted on 28th January 2011
Takes about 2 mins to read

When building forms, you will often want to only provide certain options if other options are chosen by a user. For example, there's no need to show the 'open link in new window' checkbox, if the 'make this into a link' checkbox hasn't been ticked. These kinds of dynamic forms haven't been easily available for Drupal... until now, with the #states for form elements in Drupal 7. Take a peek at this example of dynamic...

Article
Posted on 10th January 2011
Takes about 5 mins to read

What are CTools Dependencies? One of several helpers included in the ctools module, ctools dependency is described on the module page itself as "a simple form widget to make form items appear and disappear based upon the selections in another item". It's designed to make it easy and quick to hide/show form elements based on the value of other form elements in the browser using javascript. This article was written in reference to Drupal 6...

Published in: #ctools #Drupal Planet #Forms
Article
Posted on 6th March 2009
Takes about 2 mins to read

We are finding that the feature exciting most end users in Drupal 6 is the lovely new jquery based drag and drop, as seen on the blocks and menu edit pages - we will be quite happy never have to explain the concept of "weights" again. The best news is that you can add this functionality to your own forms for free - and here is how. Build and theme the form We are assuming...

Published in: #Drupal Planet #Drupal 6 #Forms #jquery