Empty field not will sent in the e-mail

How to prevent empty fields and their HTML containers from appearing in ChronoForms emails.

Overview

The issue occurs because empty form fields still send their surrounding HTML table structure, creating unwanted blank spaces in the email.
Use a conditional PHP check in the email template to only output the field's HTML row when the form data for that specific field is not empty.

Answered
en entumas 09 Aug, 2016
Hi!

I want that, in case there is an empty field in the form, not to send it in the email. How can I do it?
I know that an empty field will not be sent if it is empty, but its container will be sent. For example:
<table>
    <tr>
        <tr>{field_1}</tr>
    </tr>
    <tr>
        <tr>{field_2}</tr>
    </tr>
</table>

If I only write in in field_1, only appear this field in the email, but also appear the empty space for the structure field_2


I tried to compare with PHP, but it doesn't work. The email has error. I tried this:
<table>
    <?php
    if !({field_1}) {
    <tr>
        <tr>{field_1}</tr>
    </tr>
    }
    ?>
</table>

And this:
<table>
    <?php
    $field_1 = {field_1};
    if !($field_1) {
    <tr>
        <tr>{field_1}</tr>
    </tr>
    }
    ?>
</table>


But it doesn't work

Thanks!
Gr GreyHead 09 Aug, 2016
Answer
1 Likes
Hi entumas,

Your PHP needs fixing :-( Please try
<table>
<?php
if ( !empty($form->data['field_1']) ) {
echo "
    <tr>
        <tr>{$form->data['field_1']}</tr>
    </tr>";
}
?>
</table>

Bob
en entumas 09 Aug, 2016
Oh Bob!
As always, your answers provides the solution
Thanks thanks thanks!😀
This topic is locked and no more replies can be posted.