This project is not covered by Drupal’s security advisory policy.

This module adds the ability to encrypt supported Form API elements by adding an '#encrypt' property. It requires the Encrypt module to do the actual encryption and decryption.

The 7.x-2.x release has been refactored to work with Encrypt 2.x, meaning it now supports encryption configurations. It is also more stable, with some previously reported bugs fixed.

Using the Encrypt Form API module

After installing and enabling this module, you will be able to add an '#encrypt' property to any of the following supported Form API element types:

  • textfield
  • textarea
  • checkboxes
  • checkbox
  • radios
  • radio
  • select
  • password
  • password_confirm

In order to flag the form as having encrypted fields, set a property of '#encrypted_fields' to TRUE on the form root.

Here's an example:

function my_form($form, $form_state) {
  $form = array();

  $form['#encrypted_fields'] = TRUE;

  $form['a_text_field'] = array(
    '#type' => 'textfield',
    '#title' => t('A Sample Textfield'),
    '#default_value' => variable_get('a_text_field', ''),
    '#encrypt' => TRUE,
  );

  return $form;
}

This will encrypt the value of that field using the site's default encryption configuration. Encryption happens at the end of form validation, so other modules can still perform validation on the original, unencrypted value. Decryption should be handled for you automatically.

You may also specify the encryption configuration and options to use when encrypting a field. It is the same as above, except that #encrypt is an array:

#encrypt => array(
  'config' => 'secondary',
  'options' => array(
    'base64' => TRUE,
  ),
),

Keep in mind that if the chosen encryption method returns binary data and you plan to store it in a database, the column to save to must support binary data—a blob column type, for instance.

Encrypt Form Api was originally part of the Encrypt module.

Supporting organizations: 
sponsored development of 2.x version

Project information

Releases