• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

How do I repeat group in email template

kootjoo

Member
Hi,

I have create a custom e-mail template with placejholders. It works as it should. However I have a repeating group in it. How do I get this group to repeat? This is how the code for this group looks like:

Code:
<td colspan="2" bgcolor="#1d70b7" style="color: #FFF; font-family: Arial, Helvetica, sans-serif; font-weight: bold;">Deelnemers</td>
  </tr>
  <tr>
    <td class="form-bold"><span class="form-font">Naam</span></td>
    <td><span class="form-font">{om_aanmeldingen_8_repeat___aanhefdeelnemer} {om_aanmeldingen_8_repeat___voorletter} {om_aanmeldingen_8_repeat___naamdeelnemer}</span></td>
  </tr>
  <tr>
    <td class="form-bold"><span class="form-font">Geboortedatum</span></td>
    <td><span class="form-font">{om_aanmeldingen_8_repeat___geboortedatum}</span></td>
  </tr>
  <tr>
    <td class="form-bold"><span class="form-font">Geboorteplaats</span></td>
    <td><span class="form-font">{om_aanmeldingen_8_repeat___geboorteplaats}</span></td>
 
If you need to render repeat group data, you'll need to write a PHP template. Placeholders don't really work for repeat data.

I just need to run a quick test so I can give you some more specific advice ...

-- hugh
 
OK, so ... to write a PHP tmeplate, for the non-repeat stuff, it's more or less what you already have. You just have to replace the placeholders with little PHP snippets to echo the data ...

PHP:
    <td><span class="form-font"><?php echo $this->emailData['om_aanmeldingen_8_repeat___geboortedatum']; ?></span></td>

For the repeat data, it gets a little more complex. Instead of the $this->emailData['yourtable___elementname'] being a simple string of a single value, for a repeat group, it's an array, with as many entries as there are repeats for that group.

So the first thing you need is to to find out how many repeats the group has. Which is in $this->data['fabrik_repeat_group'][x], where x is the numeric ID of the group you are working on. That is, the numeric ID in the left most column of the Group list on the backend.

So, lets say you are working on a group with ID 123, you get the number of repeats from that 'fabrik_repeat_group' array. Then you would then loop round that many times, and render you group layout like this ....

PHP:
<?php
$repeats = $this->data['fabrik_repeat_group'][123];
for ($repeat=0; $repeat < $repeats; $repeat++) {
?>
  <table>
      <tr>
        <td>Your title:</td>
        <td><?php echo $this->emailData['yourtable___some_repeat_element'][$repeat]; ?>
      </tr>
  <table>
<?php
}
?>

... which would render a table for each of the repeats.

So ... the basic formatting is the same as your HTML template, you just need to wrap any PHP code with those open and close php tags.

-- hugh
 
Hi,

I have set the repeat group like:

HTML:
 <?php
$repeats = $this->data['fabrik_repeat_group'][12];
foreach ($repeats as $repeat) {
?>
    <td><span class="form-font"><?php echo $this->emailData['om_aanmeldingen_8_repeat___aanhefdeelnemer'][$repeat]; ?><?php echo $this->emailData['om_aanmeldingen_8_repeat___voorletter'][$repeat]; ?><?php echo $this->emailData['om_aanmeldingen_8_repeat___naamdeelnemer'][$repeat]; ?> </span></td>
  </tr>
  <tr>
    <td class="form-bold"><span class="form-font">Geboortedatum</span></td>
    <td><span class="form-font"><?php echo $this->emailData['om_aanmeldingen_8_repeat___geboortedatum'][$repeat]; ?></span></td>
  </tr>
  <tr>
    <td class="form-bold"><span class="form-font">Geboorteplaats</span></td>
    <td><span class="form-font"><?php echo $this->emailData['om_aanmeldingen_8_repeat___geboorteplaats'][$repeat]; ?></span></td>
  </tr>
  <?php
}
?>

But the group show up empty in the mail.

Also I have three fields thar are cascading dropdowns, they show up as "array"

HTML:
<td class="form-bold"><span class="form-font">Trainingsdatum</span></td>
    <td><span class="form-font"><?php echo $this->emailData['om_aanmeldingen___datum']; ?></span></td>

What am I doing wrong here
 
For the first issue, I edited my post shortly after posting, that foreach() should be a for(). Reload this page and take another look at my edited code.

Checking on the array thing. We should be providing an already formatted value in the emailData[] array.

-- hugh
 
OK, there seems to be a glitch in the getEmailValue() function for joins (and elements which extend that class, like CDD's). It's supposed to build a single rendered string, but it's building an array of strings.

Working on it.

-- hugh
 
OK, it appears I was wrong, and that getEmailValue() doesn't always return a simple string. For "list" type elements, i.e. those which can have multiple selections (radios, checkboxes, joins, etc), it'll be an array of values.

So for your "array" type elements, you'll need to do something like this:

PHP:
echo implode(', ', $this->emailData['om_aanmeldingen___datum']);

Which will render multiple selections (like checkboxes) as values separated by a comma. For single selections (like dropdowns, or joins rendered as dropdowns) it will just render the single value.

If you wanted to be more creative, you could render them as UL's, or any other formatting you wanted, like ...

PHP:
<ul>
<?php echo implode('<li>', $this->emailData['om_aanmeldingen___datum']); ?>
</ul>

In case you aren't familiar with PHP, the implode() function takes an array of values, and turns it into a single string, with each value separated by the "separator" (like the <li>, or the comma, in these examples). So imploding an array which has (say) three items, ["one", "two", "three"] with ", " as the seperator produces a single string, "One, Two, Three".

-- hugh
 
Hi,

Sorry for my late response, but I was away for some days. The array thing works great now. I have now also tested the repeat group but values do not show up in my email.

I now have:

HTML:
 <?php
$repeats = $this->data['fabrik_repeat_group'][12];
for ($repeat=0; $repeat < $repeats; $repeat++) {
?>
    <td><span class="form-font"><?php echo $this->emailData['om_aanmeldingen_8_repeat___aanhefdeelnemer'][$repeat]; ?><?php echo $this->emailData['om_aanmeldingen_8_repeat___voorletter'][$repeat]; ?><?php echo $this->emailData['om_aanmeldingen_8_repeat___naamdeelnemer'][$repeat]; ?> </span></td>
  </tr>
  <tr>
    <td class="form-bold"><span class="form-font">Geboortedatum</span></td>
    <td><span class="form-font"><?php echo $this->emailData['om_aanmeldingen_8_repeat___geboortedatum'][$repeat]; ?></span></td>
  </tr>
  <tr>
    <td class="form-bold"><span class="form-font">Geboorteplaats</span></td>
    <td><span class="form-font"><?php echo $this->emailData['om_aanmeldingen_8_repeat___geboorteplaats'][$repeat]; ?></span></td>
  </tr>
  <?php
}
?>

Thanks,
KooTjoo
 
What does it output? Does it output the right number of repeats, but with no values? Or does it just not output anything?

Can you put:

print_r($this->data);
print_r($this->emailData);

... as the first lines in that chunk of code, and paste the output here? It'll probably be a lot of data, but it should tell me everything I need to know.

-- hugh
 
Code:
Naam    Array ( [om_aanmeldingen___soortaanmelding] => Open inschrijving [om_aanmeldingen___training] => Array ( [0] => Keurmeester heftrucks ) [om_aanmeldingen___datum] => Array ( [0] => 07-05-2014 ) [om_aanmeldingen___lokatie] => Array ( [0] => Lexmond ) [om_aanmeldingen___id] => 14 [om_aanmeldingen___date_time] => 2014-04-23 [om_aanmeldingen___bedrijfsnaam] => j [om_aanmeldingen___aanhef] => Dhr. [om_aanmeldingen___contactpersoon] => k [om_aanmeldingen___adres] => k [om_aanmeldingen___postcode] => k [om_aanmeldingen___plaats] => k [om_aanmeldingen___telefoon] => k [om_aanmeldingen___email] => markoo@onlinenow.nl [om_aanmeldingen___aantal] => 1 [om_aanmeldingen___afwijkendfactuur] => Nee [om_aanmeldingen___naamfactuur] => [om_aanmeldingen___factuuradres_1] => [om_aanmeldingen___postcodefactuur] => [om_aanmeldingen___plaatsfactuur] => [om_aanmeldingen_12_repeat___id] => Array ( [0] => ) [om_aanmeldingen_12_repeat___parent_id] => Array ( [0] => 34 ) [om_aanmeldingen_12_repeat___voorletterdeelnemer] => Array ( [0] => wwww ) [om_aanmeldingen_12_repeat___naamdeelnemer] => Array ( [0] => wwwww ) [om_aanmeldingen_12_repeat___geboortedatum] => 24-04-2014 [om_aanmeldingen___opmerkingen] => [listid] => 1 [listref] => 1 [rowid] => 34 [Itemid] => 261 [option] => com_fabrik [task] => form.process [isMambot] => [formid] => 1 [returntoform] => 0 [fabrik_referrer] => http://www.omegatraining.nl/trainingen [fabrik_ajax] => 0 [package] => fabrik [packageId] => [103732ccbe60052d39d70d9088f66fab] => 1 [format] => html [fabrik_repeat_group] => Array ( [6] => 1 [7] => 1 [9] => 1 [12] => 1 [10] => 1 ) [Submit] => [om_aanmeldingen___soortaanmelding_raw] => Array ( [0] => 1 ) [om_aanmeldingen___training_raw] => Array ( [0] => Keurmeester heftrucks ) [om_aanmeldingen___datum_raw] => Array ( [0] => 2014-05-07 14:37:19 ) [om_aanmeldingen___lokatie_raw] => Array ( [0] => Lexmond ) [om_aanmeldingen___id_raw] => 14 [om_aanmeldingen___date_time_raw] => 2014-04-23 10:33:16 [om_aanmeldingen___bedrijfsnaam_raw] => j [om_aanmeldingen___aanhef_raw] => Array ( [0] => man ) [om_aanmeldingen___contactpersoon_raw] => k [om_aanmeldingen___adres_raw] => k [om_aanmeldingen___postcode_raw] => k [om_aanmeldingen___plaats_raw] => k [om_aanmeldingen___telefoon_raw] => k [om_aanmeldingen___email_raw] => markoo@onlinenow.nl [om_aanmeldingen___aantal_raw] => Array ( [0] => 1 ) [om_aanmeldingen___afwijkendfactuur_raw] => Array ( [0] => 0 ) [om_aanmeldingen___naamfactuur_raw] => [om_aanmeldingen___factuuradres_1_raw] => [om_aanmeldingen___postcodefactuur_raw] => [om_aanmeldingen___plaatsfactuur_raw] => [om_aanmeldingen_12_repeat___id_raw] => Array ( [0] => ) [om_aanmeldingen_12_repeat___aanhefdeelnemer_raw] => Array ( [0] => ) [om_aanmeldingen_12_repeat___parent_id_raw] => Array ( [0] => 34 ) [om_aanmeldingen_12_repeat___voorletterdeelnemer_raw] => Array ( [0] => wwww ) [om_aanmeldingen_12_repeat___naamdeelnemer_raw] => Array ( [0] => wwwww ) [om_aanmeldingen_12_repeat___geboortedatum_raw] => Array ( [0] => 2014-04-24 12:33:20 ) [om_aanmeldingen___opmerkingen_raw] => [__pk_val] => [179:1:0] => 6525F5957 B52 [_ga] => GA1.2.254154813.1397667807 [761b0796cbc098ae151bb9fb1a170fc4] => lnrvrfcpkvdhirr1om3ilfo485 [01f18afa67fdb08f28823249f8c1c489] => 83vfp9sct2f332ld17oj4m87k7 [view] => form [fabrik_show_in_list] => Array ( ) [om_aanmeldingen_12_repeat___aanhefdeelnemer] => Array ( [0] => ) ) Array ( [om_aanmeldingen___soortaanmelding_raw] => Array ( [0] => 1 ) [om_aanmeldingen___soortaanmelding] => Open inschrijving [om_aanmeldingen___training_raw] => Array ( [0] => Keurmeester heftrucks ) [om_aanmeldingen___training] => Array ( [0] => Keurmeester heftrucks ) [om_aanmeldingen___datum_raw] => Array ( [0] => 2014-05-07 14:37:19 ) [om_aanmeldingen___datum] => Array ( [0] => 07-05-2014 ) [om_aanmeldingen___lokatie_raw] => Array ( [0] => Lexmond ) [om_aanmeldingen___lokatie] => Array ( [0] => Lexmond ) [om_aanmeldingen___id_raw] => 14 [om_aanmeldingen___id] => 14 [om_aanmeldingen___date_time_raw] => 2014-04-23 10:33:16 [om_aanmeldingen___date_time] => 2014-04-23 [om_aanmeldingen___bedrijfsnaam_raw] => j [om_aanmeldingen___bedrijfsnaam] => j [om_aanmeldingen___aanhef_raw] => Array ( [0] => man ) [om_aanmeldingen___aanhef] => Dhr. [om_aanmeldingen___contactpersoon_raw] => k [om_aanmeldingen___contactpersoon] => k [om_aanmeldingen___adres_raw] => k [om_aanmeldingen___adres] => k [om_aanmeldingen___postcode_raw] => k [om_aanmeldingen___postcode] => k [om_aanmeldingen___plaats_raw] => k [om_aanmeldingen___plaats] => k [om_aanmeldingen___telefoon_raw] => k [om_aanmeldingen___telefoon] => k [om_aanmeldingen___email_raw] => markoo@onlinenow.nl [om_aanmeldingen___email] => markoo@onlinenow.nl [om_aanmeldingen___aantal_raw] => Array ( [0] => 1 ) [om_aanmeldingen___aantal] => 1 [om_aanmeldingen___afwijkendfactuur_raw] => Array ( [0] => 0 ) [om_aanmeldingen___afwijkendfactuur] => Nee [om_aanmeldingen___naamfactuur_raw] => [om_aanmeldingen___naamfactuur] => [om_aanmeldingen___factuuradres_1_raw] => [om_aanmeldingen___factuuradres_1] => [om_aanmeldingen___postcodefactuur_raw] => [om_aanmeldingen___postcodefactuur] => [om_aanmeldingen___plaatsfactuur_raw] => [om_aanmeldingen___plaatsfactuur] => [om_aanmeldingen_12_repeat___id_raw] => Array ( [0] => ) [om_aanmeldingen_12_repeat___id] => Array ( [0] => ) [om_aanmeldingen_12_repeat___aanhefdeelnemer_raw] => Array ( [0] => ) [om_aanmeldingen_12_repeat___aanhefdeelnemer] => Array ( [0] => ) [om_aanmeldingen_12_repeat___parent_id_raw] => Array ( [0] => 34 ) [om_aanmeldingen_12_repeat___parent_id] => Array ( [0] => 34 ) [om_aanmeldingen_12_repeat___voorletterdeelnemer_raw] => Array ( [0] => wwww ) [om_aanmeldingen_12_repeat___voorletterdeelnemer] => Array ( [0] => wwww ) [om_aanmeldingen_12_repeat___naamdeelnemer_raw] => Array ( [0] => wwwww ) [om_aanmeldingen_12_repeat___naamdeelnemer] => Array ( [0] => wwwww ) [om_aanmeldingen_12_repeat___geboortedatum_raw] => Array ( [0] => 2014-04-24 12:33:20 ) [om_aanmeldingen_12_repeat___geboortedatum] => 24-04-2014 [om_aanmeldingen___opmerkingen_raw] => [om_aanmeldingen___opmerkingen] => )
 
Hi,

My mistake!!!! THe groupid in the elemenst was wrong. The only thing that is left now is that it doesn't display the "Geboortedatum" correctly. It shows only a number and not the complete date.

Thanks and sorry, KooTjoo
 
Hmmm, for some reason the date is getting moofed up, it's not an array. I'll have a look at that, but meanwhile try using the raw data for that, by appending _raw to the element name. That seems to be correct, in an array. But it'll be a full MySQL format (Y-m-d H:i:s) format, so you'll need to run it through date formatting to get your desired format.

PHP:
<?php echo date('d-m-Y', strtotime($this->emailData['om_aanmeldingen_8_repeat___geboortedatum_raw'][$repeat])); ?>

... or whatever your desired date format is, see http://php.net/date for formats.

-- hugh
 
Hi,

Sorry to not have answered before I was away for a few days. It works like it should. Thanks!

Are there also possibillities to hide the groups that are hidden in the form in the e-mail template?

KooTjoo
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top