After installing this module I see the following errors

Notice: Undefined index: value in webform_encrypt_webform_submission_presave() (line 93 of /var/www/drupal7/sites/all/modules/webform_encrypt/webform_encrypt.module).
Warning: Invalid argument supplied for foreach() in webform_encrypt_webform_submission_presave() (line 93 of /var/www/drupal7/sites/all/modules/webform_encrypt/webform_encrypt.module).

Database:
When I try to submit the a Test form which has one File field and one Textfield selected for encryption, I see the following in the database:

mysql> select * from webform_submitted_data\G
*************************** 1. row ***************************
 nid: 1
 sid: 1
 cid: 1
  no: 0
data: 1
*************************** 2. row ***************************
 nid: 1
 sid: 2
 cid: 1
  no: 0
data: 2
*************************** 3. row ***************************
 nid: 1
 sid: 3
 cid: 1
  no: 0
data: 3
*************************** 4. row ***************************
 nid: 1
 sid: 4
 cid: 1
  no: 0
data: 5
*************************** 5. row ***************************
 nid: 1
 sid: 5
 cid: 2
  no: 0
data: This should be encrypted
*************************** 6. row ***************************
 nid: 1
 sid: 6
 cid: 2
  no: 0
data: This should be encrypted

Module Setup:
I've stayed with the out-of-the-box options for now, hoping to isolate what's happening.

$ drush vget enc
encrypt_default_config: "default"

About the environment:
This is a Drupal 7.34 install on vagrant. I'm running the following modules

vagrant@vagrant-ubuntu-trusty-64:/var/www/html$ drush pml | grep Enabled  | grep Module | grep -v Core

 Administration    Coffee (coffee)                                    Module  Enabled        7.x-2.2        
 Administration    Module filter (module_filter)                      Module  Enabled        7.x-2.0-alpha2 
 Chaos tool suite  Chaos tools (ctools)                               Module  Enabled        7.x-1.5        
 Development       Devel (devel)                                      Module  Enabled        7.x-1.5        
 Development       Module Builder (module_builder)                    Module  Enabled        7.x-2.x-dev    
 Encryption        Encrypt (encrypt)                                  Module  Enabled        7.x-2.0        
 Other             Entity API (entity)                                Module  Enabled        7.x-1.5        
 Other             Entity tokens (entity_token)                       Module  Enabled        7.x-1.5                           
 Views             Views (views)                                      Module  Enabled        7.x-3.8        
 Webform           Webform (webform)                                  Module  Enabled                       
 Webform           Webform Encrypt (webform_encrypt)                  Module  Enabled        7.x-1.0+10-dev 

Comments

rgchi’s picture

In trying to explore the issue a bit I added a dsm of what looks like the offending undefined index.


/**
 * Implementation of hook_webform_submission_presave().
 * Encrypt the value if the component has been marked as such.
 */
function webform_encrypt_webform_submission_presave($node, &$submission) {
  foreach ($submission->data as $cid => $entry) {
    if (!empty($node->webform['components'][$cid]['extra']['encrypt'])) {

      dsm($submission->data[$cid]);

      foreach ($submission->data[$cid]['value'] as $delta => $value) {
        $submission->data[$cid]['value'][$delta] = encrypt($entry['value'][$delta], array('base64' => TRUE));
        }
    }
  }
}

The DSM shows $submission->data[$cid] shows

(Array, 1 element)
    0 (String, 24 characters ) This should be encrypted

Perhaps removing ['value'] would remove that error?

rgchi’s picture

So yeah. It looks like removing the ['value'] would solve the issue of data going in at least.

$ git diff
diff --git a/webform_encrypt.module b/webform_encrypt.module
index b529696..24dece1 100644
--- a/webform_encrypt.module
+++ b/webform_encrypt.module
@@ -92,7 +92,7 @@ function webform_encrypt_webform_submission_presave($node, &$submission) {
     if (!empty($node->webform['components'][$cid]['extra']['encrypt'])) {
 
       foreach ($submission->data[$cid]as $delta => $value) {
-        $submission->data[$cid]['value'][$delta] = encrypt($entry['value'][$delta], array('base64' => TRUE));
+        $submission->data[$cid][$delta] = encrypt($entry[$delta], array('base64' => TRUE));
         }
     }
   }

alexgreyhead’s picture

Version: 7.x-1.x-dev » 7.x-1.1
Priority: Normal » Critical

I've also run into this problem and, from what I can tell, it's a critical bug in the latest 1.1 release because the data simply isn't being encrypted, hence changing the status.

Thanks for your investigation work, rgchi.

I don't know who the maintainer is otherwise I'd be happy to give them a gentle nudge that this is happening.

Alex

alexgreyhead’s picture

Just to clarify, I can confirm the patch in #2 fixes my problem and data is saved correctly.

Now I just need to fix the problem that e-mails are being sent with an encrypted "from" name. :) :(

th_tushar’s picture

Hello All,

Got the following errors/warnings while webform submission using webform_encrypt module,

Notice: Undefined index: value in webform_encrypt_webform_submission_presave() (line 93 of /var/www/drupal7/sites/all/modules/webform_encrypt/webform_encrypt.module).
Warning: Invalid argument supplied for foreach() in webform_encrypt_webform_submission_presave() (line 93 of /var/www/drupal7/sites/all/modules/webform_encrypt/webform_encrypt.module).
Notice: Undefined index: value in webform_encrypt_webform_submission_presave() (line 93 of /var/www/drupal7/sites/all/modules/webform_encrypt/webform_encrypt.module).
Warning: Invalid argument supplied for foreach() in webform_encrypt_webform_submission_presave() (line 93 of /var/www/drupal7/sites/all/modules/webform_encrypt/webform_encrypt.module).
Notice: Undefined index: value in webform_encrypt_webform_submission_load() (line 109 of /var/www/drupal7/sites/all/modules/webform_encrypt/webform_encrypt.module).
Warning: Invalid argument supplied for foreach() in webform_encrypt_webform_submission_load() (line 109 of /var/www/drupal7/sites/all/modules/webform_encrypt/webform_encrypt.module).
Notice: Undefined index: value in webform_encrypt_webform_submission_load() (line 109 of /var/www/drupal7/sites/all/modules/webform_encrypt/webform_encrypt.module).
Warning: Invalid argument supplied for foreach() in webform_encrypt_webform_submission_load() (line 109 of /var/www/drupal7/sites/all/modules/webform_encrypt/webform_encrypt.module).

The attached patch will fix the issue.

Thanks,
Tushar

th_tushar’s picture

Status: Active » Needs review
vj’s picture

Status: Needs review » Reviewed & tested by the community

I have tested this patch and resolves issue.

miloshito’s picture

patch worked for me. However after i received a HMAC error.

  • th_tushar committed 1fcf21b on 7.x-1.x
    Issue #2413111 by th_tushar: Undefined index, value in...
th_tushar’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x-1.2 version. Marking it as fixed.

Status: Fixed » Closed (fixed)

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