Only send filled variables in email

ltempest 24 Aug, 2016
Hello,
Is it possible to add code to the HTML email being sent that will only include values from the form that have been filled in?

I have a larger form with many input boxes, with only some of them being filled in on each submission. However the email includes all the fields whether completed or not.

is it possible to only display the completed fields in the email being sent?

Thanks

Lee
GreyHead 24 Aug, 2016
Hi Lee,

Yes, you use PHP in a Custom Code action or in the Email template to check if there is a response. You'll find examples of the code in the forums here if you need it.

Bob
ltempest 25 Aug, 2016
Bob,
Thanks for the reply, I've tried to search for examples throughout the forum and used some of them to no success!

I currently have:


<?php if(!empty($form->data["{SSS-HPLB}"]) || !empty($form->data["{MSS-HPLB}"]))
 echo '<tr>
	<td>Roofing Product Line Brochure</td><td>{SSS-HPLB}</td><td>{MSS-HPLB}</td><td> </td>
</tr>';
endif; ?>


But when I try and submit the form I get this error:

Mailer Error: Message body empty

Any advice? what have a I done wrong?
GreyHead 25 Aug, 2016
Hi Lee,

You can't use the ChronoForms {} syntax in PHP* :-( Please try this version
<?php
if (!empty($form->data['SSS-HPLB']) || !empty($form->data['MSS-HPLB']) ) {
 echo "<tr>
   <td>Roofing Product Line Brochure</td>
  <td>{$form->data['SSS-HPLB']}</td>
  <td>{$form->data['SSS-HPLB']}</td><td> </td>
</tr>'";
}
?>
Note that this may still give you an error if one of the two variables does not exist in the form data (if it's there but empty it will be OK).

Bob

* You can use the *different* PHP {} syntax inside double quotes e.g.
echo "xxx{$some_variable}yyy";
ltempest 25 Aug, 2016
Bob,
Thanks for the reply I'll give it a try.

I was trying to reduce the amount of empty boxes in the email being sent, if you take a look at the attached this is the entire form. it is highly unlikely a customer will order everything and will probably only order one or two items.

I wanted to remove the rows that are not filled in so the end user and my client do not get a long email with lots of blank space!

Does that make sense?
GreyHead 25 Aug, 2016
Hi Lee,

Yes, that makes sense.

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