ChronoEngine.com homepage

Forums

Please write a review for the extension you are using on the Joomla extensions directory before posting a new question as we are being spammed by many negative reviews.

Thank you for your support!

Weird custom email template when fields are deliberately left blank

jdran 11 Nov, 2015
I have made up a custom template like this example below:

p><b>To: {recipient_name}</b><br>
A message was sent to you from website:<br>
<b><i>www.example.com</i></b>:</p>
<table>
<tr><td>Full Name</td><td><i>{fullname}</i></td></tr>
<tr><td>Email</td><td><i>{email}</i></td></tr>
<tr><td>Address</td><td><i>{address}, {number}</i></td></tr>
</table>

for example, as address is not required, if someone leaves blank one of the two (address or number) the template returns a strange output:

Full Name Example Name
Email examplemail@mail.com
Address ,4

or

Full Name Example Name
Email examplemail@mail.com
Address Avenue Street,

in each case the comma is always there, pesky and meddlesome. Is there any way to avoid such a thing?
jdran 11 Nov, 2015
I suspect that the solution might be similiar with this with use of a custome code. But I don't know how to achieve this.
GreyHead 11 Nov, 2015
1 Likes
Hi jdran,

Please try this in a Custom Code action
<?php
if ( empty($form->data['address']) && empty($form->data['number']) ) {
  $form->data['address_number'] = '';
} else if ( empty($form->data['address']) ) {
  $form->data['address_number'] = $form->data['number'];
} else if ( empty($form->data['number']) ) {
  $form->data['address_number'] = $form->data['address'];
} else {
  $form->data['address_number'] = $form->data['address'].', '.$form->data['number'];
}
?>
Then put {address_number} in the email template.

Bob
jdran 11 Nov, 2015
Thank you! Seems the right thing, I ll test it and I ll be get back if there's any problem!
Cheers
This topic is locked and no more replies can be posted.

2Checkout.com

2CheckOut.com Inc. (Ohio, USA) is an authorized retailer for goods and services provided by ChronoEngine.com