handle subarray

livingwebstudio 28 Dec, 2015
Hi,
I have a form with a multiplier container that has the email of author
with the array, I save this information in a specific DB
 [autori] => Array
        (
            [1] => Array
                (
                    [record_id] => 131
                    [autoriemail] => dfdfdf@f.it
                )

            [2] => Array
                (
                    [record_id] => 131
                    [autoriemail] => hhhhh@hljk.it
                )

            [id] => 58
        )

It's possible to send an email to each user? I think that I set up a handle of array.. but it doesn't work.
Anybody can help me?
GreyHead 28 Dec, 2015
Answer
1 Likes
Hi livingwebstudio,

Please try this in a Custom Code element before the Email action
<?php
$form->data['autori_email'] = array();
foreach ( $form->data['autori'] as $a ) {
  $form->data['autori_email'][] = $a['autoriemail'];
}
?>
Then put autori_email in the Dynamic To Email box, I think that will accept an array.

Bob
livingwebstudio 28 Dec, 2015
thanks a lot for your php code.. it's great!
Unfortunately email action doesn't accept array data; I have to handle array "autori_email" (with a specific action) and it works. this is the code:
[autori_email] => ghghgh@kkl.it,ghghdgh@kkl.it,ghghgh@kkl.it6

 [Email] => Array
                (
                    [0] => An email with the details below was sent successfully:
                    [1] => To:
                    [2] => Subject:
                    [3] => From name:gfgfgfg
                    [4] => From email:ffgfgg@hoho.iu
                    [5] => CC:
                    [6] => BCC:ghghgh@kkl.it, ghghdgh@kkl.it, ghghgh@kkl.it6
                    [7] => Reply name:
                    [8] => Reply email:
                    [9] => Attachments:
                    [10] => Array
                        (
                        )

                    [11] => Body:
fgfgfgfg
GreyHead 28 Dec, 2015
1 Likes
Hi livingwebstudio,

You can alter my code to build a comma separated list
<?php
$form->data['autori_email'] = array();
foreach ( $form->data['autori'] as $a ) {
  $form->data['autori_email'][] = $a['autoriemail'];
}
$form->data['autori_email'] = implode(',', $form->data['autori_email']);
?>

Bob
This topic is locked and no more replies can be posted.