You are here

function encryptfapi_test_form in Encrypt Form API 7.2

The form.

1 string reference to 'encryptfapi_test_form'
encryptfapi_menu in tests/encryptfapi_test.module
Implements hook_menu().

File

tests/encryptfapi_test.module, line 28
Declares a form to test Form API encryption.

Code

function encryptfapi_test_form() {
  $form = array();
  $form['#encrypted_fields'] = TRUE;
  $element_types = _encryptfapi_test_form_element_types();
  $test_types = _encryptfapi_test_test_types();

  // Set up three fields for each supported element type:
  // default, specified, and nested.
  foreach ($element_types as $name => $element_type) {
    foreach ($test_types as $test_type) {
      $field_id = "encryptfapi_test_{$name}_{$test_type}";
      if ($test_type == 'nested') {
        $form["{$field_id}_container"] = array(
          '#type' => 'container',
          '#tree' => TRUE,
        );
        $field =& $form["{$field_id}_container"][$field_id];
      }
      else {
        $field =& $form[$field_id];
      }
      $field = array(
        '#type' => $name,
        '#title' => ucwords($element_type['label']) . ' ' . ucwords($test_type),
        '#encrypt' => TRUE,
      );
      if ($test_type == 'specified') {
        $field['#encrypt'] = array(
          'config' => 'default',
          'options' => array(
            'base64' => TRUE,
          ),
        );
      }
      else {
        $field['#encrypt'] = TRUE;
      }
      if (isset($element_type['options']) && $element_type['options'] === TRUE) {
        $field['#options'] = _encryptfapi_test_form_element_options();
      }
      if (in_array($name, array(
        'checkbox',
        'radio',
      ))) {
        $field['#return_value'] = 1;
      }
      if (!isset($element_type['default_value']) || $element_type['default_value'] !== FALSE) {
        if ($test_type == 'nested') {
          $default_value = variable_get("{$field_id}_container", array());
          $default_value = isset($default_value[$field_id]) ? $default_value[$field_id] : '';
        }
        else {
          $default_value = variable_get($field_id, '');
        }
        $field['#default_value'] = $default_value;
      }
    }
  }
  return system_settings_form($form);
}