When printing multi-valued fields in notification emails, only the first value gets printed.

I've traced this back to the token replacement of the [entityform:entityform-submitted-data]token, used in the email variable. Lines 198-206 of the entityform_tokens() function in entityform.module are the problem, I believe:

if (!empty($items)) {
    $autofields[$field_display['weight']] = array(
        'field_name' => $instance['field_name'],
        'options' => array('type' => $field_display['type'], 'settings' => $field_display['settings']),
    );

    $autofields[$field_display['weight']] = field_view_value('entityform', $entityform, $instance['field_name'], $items[0], $field_display);
    $autofields[$field_display['weight']]['#title'] = $instance['label'];
}

This line, gets only the first field value ($items[0]):

$autofields[$field_display['weight']] = field_view_value('entityform', $entityform, $instance['field_name'], $items[0], $field_display);

I propose replacing lines 198-206 with the following, which adds the render array for each field value to the $autofields array:

if (!empty($items)) {
    $field = array();
    foreach($items as $count=>$item) {
      $field[$count] = field_view_value('entityform', $entityform, $instance['field_name'], $items[$count], $field_display);
    }

    $autofields[$field_display['weight']] = $field;
    $autofields[$field_display['weight']]['#title'] = $instance['label'];
}
CommentFileSizeAuthor
#10 1969014-multivalue-10.diff1.15 KBimpleri
#6 multivalue.diff785 bytesimpleri
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bjcooper’s picture

Making this change may also require you to update entityform-submittd-data.tpl.php so that multi-value fields don't have all their values rendered one-after-the-other on one line.

I'd suggest changing line 28:

<p><?php print render($field); ?></p>

To something like this:

<p>
<?php foreach(element_children($field) as $val): ?>
<?php print render($field[$val]); ?><br/>
<?php endforeach; ?>
</p>
tedbow’s picture

I haven't had time to look at this yet but for 2.x I am thinking of removing the token functionality from Entityform an putting it into this module - http://drupal.org/sandbox/tedbow/1674042

The idea is that is more generalized functionality that should work for any fieldable entity. It provides a token for the text output of every entity type and every view mode.

It has been awhile since I wrote the code. So it might be updated with the logic from this module.
Right now Entity to Text actually tries to convert an renderable array of the Entity output text.

The way the token works in Entityform is that it gets the field values and outputs them directly.

The Entity to Text module would only be required for Entityform Notifications.

Can you check to see if the tokens provided by that module work for you?

tedbow’s picture

I haven't had time to look at this yet but for 2.x I am thinking of removing the token functionality from Entityform an putting it into this module - http://drupal.org/sandbox/tedbow/1674042

The idea is that is more generalized functionality that should work for any fieldable entity. It provides a token for the text output of every entity type and every view mode.

It has been awhile since I wrote the code. So it might be updated with the logic from this module.
Right now Entity to Text actually tries to convert an renderable array of the Entity output text.

The way the token works in Entityform is that it gets the field values and outputs them directly.

The Entity to Text module would only be required for Entityform Notifications.

Can you check to see if the tokens provided by that module work for you?

LulzCannon’s picture

Status: Needs review » Needs work

@bjcooper

Hello, I'm working with tedbow and it would help if you submit a patch file

Thank You For Your Understanding

LulzCannon’s picture

I have confirmed the problem

impleri’s picture

Version: 7.x-1.0 » 7.x-1.x-dev
Status: Needs work » Needs review
FileSize
785 bytes

Why not just used field_view_field() instead of field_view_value()?

gmclelland’s picture

@impleri - I manually applied the code in your patch since it was so small. It did work for my case, the multivalue form values came through in the email. The only problem is that the formatting was messed up. It printed the field labels twice in the email for each field.

Here is an example of what was printed in the email:

-------- TIME THIS HAPPENED: -------------------------------------------------


.... Time this happened

8:00PM
-------- DATE THIS HAPPENED: -------------------------------------------------


.... Date this happened

Thursday, September 12, 2013

Any suggestions on how to prevent this?

gmclelland’s picture

For anyone who wants a quick fix on the 1.x-branch.

Download https://drupal.org/project/entity2text
Go to /admin/config/system/variable/module
Edit the correct Email variable - in my case "Email Entityform Admin"
Change the body of the email to use [entityform:textexport-email] instead of [entityform:entityform-submittd-data]

Hope that helps

tedbow’s picture

Thanks for mentioning entity2text. that is my project that takes the logic out of Entityform. I think that is the better way to go.

impleri’s picture

FileSize
1.15 KB

It's coming out twice because entityform-submittd-data.tpl.php explicitly renders the title as an h2 tag before rendering the entire field. I'm not entirely sure how to render the title separately without doing something horribly bad (i.e. hardcoding the HTML for #title in entityform.module or removing $field['#title'] before render($field) in entityform-submittd-data.tpl.php). I'd think changing the template would be preferable to hardcoding in the module file. I've added to the #6 an unset in the template.

impleri’s picture

Issue summary: View changes

Changing back-ticks to code tags.

tedbow’s picture

Status: Needs review » Closed (works as designed)

@impleri or whoever might find this.
You can override entityform-submittd-data.tpl.php in your theme or use preprocess functions

mibfire’s picture

@impleri This way the ":" wont be removed after the title.