function _encryptfapi_encrypt_element in Encrypt Form API 7.2
Helper function to recursively process an element for encryption.
Parameters
$element: The element to process.
1 call to _encryptfapi_encrypt_element()
- _encryptfapi_form_validate in ./
encryptfapi.module - Form validation callback.
File
- ./
encryptfapi.module, line 54 - Main module file for Encrypt Form API.
Code
function _encryptfapi_encrypt_element(&$element, &$form_state) {
$element_types =& drupal_static(__FUNCTION__);
if (!isset($element_types)) {
$element_types = _encryptfapi_supported_element_types();
}
foreach (element_children($element) as $key) {
$child =& $element[$key];
if (is_array($child)) {
_encryptfapi_encrypt_element($child, $form_state);
}
// If the element is not marked for encryption or if it's not a type
// supported by this module, skip it.
if (!isset($child['#encrypt']) || $child['#encrypt'] != TRUE || !in_array($child['#type'], $element_types)) {
continue;
}
$value = drupal_array_get_nested_value($form_state['values'], $child['#parents']);
// If the value is empty, skip it.
if (empty($value)) {
continue;
}
// Encrypt the value.
$value = _encryptfapi_encrypt_element_value($child, $value);
// If encryption failed, display an error.
if (empty($value)) {
form_error($child, t('The field %field could not be encrypted.', array(
'%field' => $child['#title'],
)));
}
else {
drupal_array_set_nested_value($form_state['values'], $child['#parents'], $value);
}
}
}