View source
The #encrypt Form API property allows developers to encrypt and decrypt form elements easily. You may use the #encrypt property on textfields, textareas, select fields, checkboxes, radios, and password fields.
Here's an example of how to implement it:
<pre>
function my_form($form, $form_state) {
$form = array();
$form['#encrypted_fields'] = TRUE;
$form['textfield'] = array(
'#type' => 'textfield',
'#title' => t('A Sample Textfield'),
'#default_value' => variable_get('a_text_field', ''),
'#encrypt' => TRUE,
);
return $form;
}
</pre>
This will encrypt the value of that field using the site's default encryption configuration. Encryption happens during element validation (after form validation), so you can still validate the original, encrypted value in the form's validation stage. 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:
<pre>
#encrypt => array(
'config' => 'secondary',
'options' => array(
'base64' => TRUE,
),
),
</pre>