Remove form fields without content from data array before mail sent

Er Erik66 20 May, 2021
Hello all,
​
I have a form where I want to remove all empty fields from the {data:} array after the form is posted and before any email is sent, as I do not wish any empty fields to appear in the email. How do I go about that? Does someone have a suggestion on how to achieve that?

Thanks in advance
​
Erik
Gr GreyHead 22 May, 2021
Hi Erik,
​
You could use custom PHP to loop through the form data array and unset any empty values. I think that will do what you need.
​
Bob
Er Erik66 22 May, 2021
Hi Bob, thank you for your suggestion. I've actually tried something similar using the PHP array_filter() function. In the actions, I added the following custom code prior to any action:

$this->data = array_filter($this->data, function($value) { return !is_null($value) && $value !== ''; });
​
This code succesfully removes any key/value pair where the value is empty. I checked that by then adding a print_r($this->data) before and after the above function, and comparing the results.
​
However, the email sent as an action after this custom code, contains all data from the original data array, including the key/value pairs with no values. Which makes me think I either used the wrong data array, or the email action fetches the data array prior to the action, or.... ?
​
Erik
This topic is locked and no more replies can be posted.