Hi Folks
I have been trying for hours and searching the forums and web for answers and come up with nothing, hope you can help, because it seems like such a simple problem.
I have a form with a number of text fields that all default to '0', I only want them included in the email if they have been modified.
I have written the following PHP code in the email template which check each of the specified fieldnames to test whether it's value is zero, which works, but I cannot figure out how to display that items label (because the fieldname does not look nice in the email, since it cannot have spaces etc.)
I have been trying for hours and searching the forums and web for answers and come up with nothing, hope you can help, because it seems like such a simple problem.
I have a form with a number of text fields that all default to '0', I only want them included in the email if they have been modified.
I have written the following PHP code in the email template which check each of the specified fieldnames to test whether it's value is zero, which works, but I cannot figure out how to display that items label (because the fieldname does not look nice in the email, since it cannot have spaces etc.)
<?php
$shoppinglist = array(
'item1fieldname',
'item2fieldname',
'item3fieldname'
);
foreach ( $shoppinglist as $v ) {
if ("{$form->data[$v]}" != "0") {
echo "$v : {$form->data[$v]}<br>";
}
}
?>
Hi Jason,
You will have to hardcode the labels as well:
Regards,
Max
You will have to hardcode the labels as well:
<?php
$shoppinglist = array(
'item1fieldname' => 'Text label',
'item2fieldname' => 'Text label',
'item3fieldname' => 'Text label',
);
foreach ( $shoppinglist as $v => $label) {
if ("{$form->data[$v]}" != "0") {
echo $label." : ".$form->data[$v]."<br>";
}
}
?>
Regards,
Max
Thanks for your response Max, that really helped me.
Do you think that this is the best method to retrieve only the fields that have been completed? It would be nice if there was a way that didn't require so much hard-coding.
Regards
Jason
Do you think that this is the best method to retrieve only the fields that have been completed? It would be nice if there was a way that didn't require so much hard-coding.
Regards
Jason
Hi Jason,
It depends on how you are using this form but often the easiest way to handle this kind of form is to store the underlying data in a database table and then load the data from the table to populate the form and again to run the checks to format the output, That takes more work up-front -but afterwards you can change items or labels by updating the source table.
Bob
It depends on how you are using this form but often the easiest way to handle this kind of form is to store the underlying data in a database table and then load the data from the table to populate the form and again to run the checks to format the output, That takes more work up-front -but afterwards you can change items or labels by updating the source table.
Bob
Ok, thanks GreyHead, I had a feeling that would be the answer 😉 If my form grows much more or starts needing frequent updates then I guess I will have to invest the time into learning how to import databases.
This topic is locked and no more replies can be posted.