Conditional statements in email templates?

coolgrafix 10 Dec, 2008
New ChronoForms user.

Ok, so I'm assuming there is no way to conditionalize items in an email template. Is that correct? Example:

In the following, I'd like to not show the comma if the value of address2 is empty...

Address: {address1}, {address2}

I've seen some other posts talking about using the OnSubmit block to execute some PHP code to combine field values for the subject, but I don't think that particular example would work here. I'm probably missing something.

What are recommended workarounds?

Thanks,
Brad =)
GreyHead 11 Dec, 2008
Hi Brad,

You can make the email templates fully conditional - but not by using the {field_name} short cuts. Instead you have to create PHP variables then you can process these as much as you like.
<?php
$field_name =& JRequest::getVar('field_name', 'default value', 'post');
if ( $field_name == 'default value') {
    echo "<p>There is no value to this field!</p>";
} else {
    echo $field_name;
}
?>
NB This is a bit of pseudo-code just to give you the idea.

Bob
mingus 12 Dec, 2008
Hi

I'm trying to have some conditionnal statement in the email template in order to control the output based on the form input.
I have tryed to insert the code you have shown in the email template editor but that it messes it up...do I miss something?
How can I insert a custom PHP code in the email template?
<?php
$field_name =& JRequest::getVar('lar', 'default value', 'post');
if ( $field_name == 'default value') {
echo 'There is no value to this field!';
} else {
echo $field_name;
}
?>



Regards

Luca
GreyHead 12 Dec, 2008
Hi Luca,
When you say 'it messes up' - what happens?

Bob
mingus 12 Dec, 2008
Hi GreyHead

I solved that problem and I was able to make a multipage little application..., I didn't know it was necessary to disable the template editor in prev tab in order to put some code generating the email template.. .
Just as a suggestion, I experienced a lot of problem to set my form up as all italian chars with accent like è,à,ù ...are generating a lot of errors...
Also special html symbols as è do not work correctly in the template...
This make a little more complicate to design a form using a regular html editor and re-use existing code, as that needs to be cleaned otherwise it get chunked and it is not easy to understand where and why...

Thank you again for your help

Regards

Luca
Max_admin 12 Dec, 2008
Hi Luca,

Just as a suggestion, I experienced a lot of problem to set my form up as all italian chars with accent like è,à,ù ...are generating a lot of errors...
Also special html symbols as è do not work correctly in the template...



this is where ? in the HTML code box or the template ? did you design your template or let Chronoforms generate it auto. ?

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
mingus 12 Dec, 2008
Hi Max

either in the HTML and email template.
What happens is that the code get chunked...
Also I had a problem that the fields parsing in the autogenerated code tab were not complete and I could not save any variation...
Strangly the same problem was happening with code such as   and a char like this – ....
My code was xhtml when I have pasted in there.
I was not using the wizard.

Luca
Max_admin 13 Dec, 2008
Thank you, can you show me a code piece of this to try ? I think the problem is with using the tinymce editor, fields names can't contain any special chars too!

Regards

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
mingus 14 Dec, 2008
Hi Max

just try with the following example...

<p>
 il mio cognome e'   <input name="cognome" type="text" value="il mio cognome non è segreto" size="10" /><br />
il mio nome è:  <input name="name" type="text" value="il mio nome è segreto" size="10" /><br />
perchè il form non funziona? perchÈ è in italiano?<br />
<input name="submit" type="submit" value="invia richiesta" /><br />
</p>

check either the form html code and the email template...
Of course, if you replace al "è" with e' it works, but if you use an existing form you can get a lot of errors...
regards
Max_admin 14 Dec, 2008
Hi, I just pasted this code in a form HTML box and saved and viewed it, its very fine, fields are published with data too and tutto bene!!🙂

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger