By Alvin Alexander. Last updated: June 4, 2016
Drupal form fields FAQ: What is the syntax to make a Drupal form field (textfield, textarea, password field) required?
To make a Drupal form field required, just use the Drupal form #required attribute, as shown in this required textfield example:
$form['first_name'] = array(
'#title' => t('First Name'),
'#type' => 'textfield',
'#required' => TRUE,
);
As you can see, to set a Drupal form field to be required, you just need to add the #required form attribute, and set it to TRUE.

