I'm using system_settings_form. If I do something like this:

$form['my_secret_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Secret Key'),
    '#default_value' => variable_get('my_secret_key', ''),
    '#encrypt' => TRUE
 );
 $form['my_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Just Plain Text'),
    '#default_value' => variable_get('my_text', ''),
  );

And set an error on 'my_text' in a validation handler, all the text in 'my_secret_key' gets wiped out.

Comments

greggles’s picture

Component: Code » Encrypt FAPI module

I've never really used the encrypt fapi sub-module so it's hard to guess where the problem is. If you can provide a patch I will try to review/commit it.

bennybobw’s picture

Title: Setting an error on another field in system_settings_form wipes out fields with encrypt » Setting an error on another field out FAPI element values with encrypt
Component: Encrypt FAPI module » Code

I didn't get around to fixing the bug yet, but I did confirm that this also appears on regular forms not just the system_settings_forms. I changed the issue title to show this.

Here's a simple example:

function encrypt_fapi_test($form, &$form_state) {
  $form['encrypt_fapi_test_key'] = array(
    '#type' => 'textfield',
    '#title' => t('Secret Key'),
    '#default_value' => variable_get('encrypt_fapi_test_key', ''),
    '#encrypt' => TRUE
  );
  
  $form['encrypt_fapi_test_url'] = array(
    '#type' => 'textfield',
    '#title' => t('Test URL'),
    '#default_value' => variable_get('encrypt_fapi_test_url', ''),
  );
  
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'submit'
  );
  return $form;
}

function encrypt_fapi_test_validate($form, &$form_state) {
  if (!drupal_valid_path($form_state['values']['encrypt_fapi_test_url'])) {
    form_set_error('encrypt_fapi_test_url', t('You must enter a valid path for the Test URL'));
  }
}
greggles’s picture

Title: Setting an error on another field out FAPI element values with encrypt » Setting an error on another field removes FAPI element values with #encrypt
Component: Code » Encrypt FAPI module

Thanks for the update and the simplified test case.

greggles’s picture

To be honest, I'm thinking that maybe the encryptfapi module should be un-supported. Encryption is not the kind of thing to do partway. I don't use that module so I don't have motivation to test/support it. If someone else wants to take it on that would be great.

rlhawk’s picture

Project: Encrypt » Encrypt Form API
Version: 7.x-2.x-dev »
Component: Encrypt FAPI module » Code
Issue summary: View changes

Moving from Encrypt to Encrypt FAPI.

rlhawk’s picture

I can confirm this bug. The problem seems to be caused by _encryptfapi_element_prerender(), but I'm not entirely certain yet what needs to be done to fix it.

rlhawk’s picture

Version: » 7.x-2.x-dev

I have rewritten the module and this bug should not be an issue any longer.

rlhawk’s picture

Status: Active » Fixed

I'm going to assume that this is fixed, but re-activate the issue if not.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.