Hide empty fields in email

roman5527 05 Feb, 2020
Hi, i used code which i find on this forum for remove empty fields in email :
<?php if(!empty($form->data["field_name"])): ?>{field_name}<?php endif; ?>

My template is - example : ( i change it on tab Pages and nex tab Template : https://prnt.sc/qy5eh1 )
<?php if(!empty($form->data["titul"])): ?>
<tr>
<td width="100%">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr style="background-color:#fafafb">
<td style="padding:7px;"><strong>Titul</strong></td>
</tr>
<tr>
<td style="padding:7px;">{data:titul}</td>
</tr>
</table>
</td>
</tr>
<?php endif; ?>

But when this filed is not empty i dont see it in email too. Can you help me fix it please ? thanks
healyhatman 06 Feb, 2020
$this->data('field_name') not $form->data['fieldname']
roman5527 07 Feb, 2020
Thanks .

I have one next question .

i have in template if conditionals example :

<?php if($this->data["sluzba"] = "servis_pravidelny"): ?>
...
...
...
<?php endif; ?>
<?php if($this->data["sluzba"] = "pneuservis"): ?>
...
...
...
<?php endif; ?>
<?php if($this->data["sluzba"] = "nahradne_vozidlo"): ?>
...
...
...
<?php endif; ?>

but in email i see last value only . how i can fix it thanks .
roman5527 08 Feb, 2020
Thanks healyhatman .

Can I show in Email not value but show value from frontend for dropdown .

Example dropdown:
material=Materiál
pneuservis=Pneuservis
nahradne_vozidlo=Náhradné vozidlo

I want show in email Náhradné vozidlo , not nahradne_vozidlo.

Can I do it ? thanks
healyhatman 09 Feb, 2020
No. You have to do it again - like
$values = [ ''material' => 'Materiaaaal', 'pneuservis' => 'Pneuservis', etc etc ];
echo $values[$this->data('field_name')] ?? 'Invalid selection';
amheng5 12 Aug, 2021
Question. Can this PHP be used when creating TCPDF File to hide empty fields? I tried to enter same code used in email message (works great) but not for TCPDF. Thank you
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger