Hello all,
Found a minor issue while trying to add a fieldset element. It appears since 'fieldset', 'file', 'markup', 'pagebreak' elements do not have the option to be encrypted, when the form goes through the webform_encrypt_webform_component_presave() function you get the fallowing error Undefined index: encryption in webform_encrypt_webform_component_presave( (/sites/all/modules/webform_encrypt/webform_encrypt.module) on line 50.

I had also previously edited the module to fix a different error discussed here: http://drupal.org/node/1196126

After going through the module I think I have an idea on how it could be fixed. I will test my solution and post afterwards but I'm open to suggestions.

CommentFileSizeAuthor
#12 1344804-12.patch582 bytesl0ke
#5 1344804.patch587 bytesakoepke

Comments

timbhowe’s picture

Issue tags: +webform encrypt

Ok this is my current solution. On line 18 modify the webform_encrypt_form_alter() to add the encryption check box but disable and with a default value of 0 on 'fieldset', 'file', 'markup', 'pagebreak' form elements.

function webform_encrypt_form_alter(&$form, $form_state, $form_id) {
  // Add our fields to the component add/edit form.
  if ($form_id == 'webform_component_edit_form') {

    $component = $form_state['build_info']['args'][1];

    // Exclude webform component types that don't make sense to encrypt.
    $excluded_types = array('fieldset', 'file', 'markup', 'pagebreak');
    if (in_array($form['type']['#value'], $excluded_types)) {
	// Add settings for encryption.
      $form['encryption'] = array(
        '#type' => 'fieldset',
        '#title' => t('Encryption'),
        '#tree' => TRUE,
      );
      $form['encryption']['encrypt'] = array(
        '#type' => 'checkbox',
        '#disabled' => TRUE,
        '#title' => t('Encrypt this field\'s value'),
        '#description' => t('This form element can NOT be encrypted, !link to edit encryption settings.', array('!link' => l('Click here', 'admin/config/system/encrypt'))),
        '#default_value' => 0,
      );
	}else{
      // Add settings for encryption.
      $form['encryption'] = array(
        '#type' => 'fieldset',
        '#title' => t('Encryption'),
        '#tree' => TRUE,
      );
      $form['encryption']['encrypt'] = array(
        '#type' => 'checkbox',
        '#title' => t('Encrypt this field\'s value'),
        '#description' => t('!link to edit encryption settings.', array('!link' => l('Click here', 'admin/config/system/encrypt'))),
        '#default_value' => isset($component['extra']['encrypt']) ? $component['extra']['encrypt'] : 0,
      );
    }

  }
}

I did this so that the user would know that this type of element can't be encrypted but that the module is running. If any one has an alternative solution please feel free to share.

Thanks, hope to see this in the next release.
Tim

timbhowe’s picture

Status: Active » Needs review
akoepke’s picture

I found a similar issue with the markup field. In this case there is extra data (format of the markup) which is wiped out due to the way the webform_encrypt_webform_component_presave function is written.

Not having the encryption form element isn't an issue, I think it is easier to just check if this data exists when doing the presave.

function webform_encrypt_webform_component_presave(&$component) {
  if (!empty($component['encryption'])) {
    $component['extra'] = array_merge($component['extra'], $component['encryption']);
    unset($component['encryption']);    
  }
}

This just requires one extra line (not counting the closing bracket) and resolves both of our problems.

akoepke’s picture

Title: Encrypt option missing on fieldset form element causes issue. » Add check for encryption options to webform_encrypt_webform_component_presave()
akoepke’s picture

StatusFileSize
new587 bytes

I have rolled a proper patch for my edit which is attached to this post. This patch was created using the current dev version.

akoepke’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
cviccaro’s picture

akoepke, the patch worked perfectly to resolve the undefined index: 'encryption' errors. Thanks!

pebosi’s picture

Status: Needs review » Reviewed & tested by the community

Works for me, too.

dandaman’s picture

This worked for me and I believe it also fixes the problem in here:
#1511826: Select List and Conditional Rules not saved
Actually, I wrote my own and used isset() instead of empty(). I think that's better because empty() will throw a notice or warning or something if the array key doesn't exist, right?

akoepke’s picture

As per the PHP manual (http://php.net/empty) empty doesn't throw any warnings
empty() is the opposite of (boolean) var, except that no warning is generated when the variable is not set.

isset and empty are similar, empty is just a bit broader in scope (ie if array key exists but has no values assigned to it.)

theunraveler’s picture

Status: Reviewed & tested by the community » Closed (fixed)

Fixed in 7.x-1.x and 6.x-1.x. They will be included in the next release.

Thanks for the patches and discussion.

l0ke’s picture

Issue summary: View changes
StatusFileSize
new582 bytes

There is webform_encrypt.module.orig file name in previous patch< so I change it to webform_encrypt.module.

naiduharish’s picture

Hi @theunraveler,

What is the impact of using is_array instead of !empty() condition in the patch.