Add php in email (setup submit)

Execute PHP code in ChronoForms v6 email templates.

Overview

In CF v6, PHP code placed directly in email templates is not executed, unlike in version 5.
Create a PHP Logic Event to process your conditions and return values, then reference that event's output in your email using the {var:event_name} placeholder. For checking multiple fields efficiently, define a single PHP function that accepts dynamic parameters and call it for each field using the {fn:function_name$param=value} syntax.

Answered
ChronoForms v6
ju juansolos 30 Aug, 2017
Hi,
i try to insert php code in the email as i was doing with cfv5.
Example check existing value :
<?php if(!empty($form->data["address"])): ?>
Adresse : {address} <br/>
<?php endif; ?>

But in cfv6 php in not executed.
Any help

Regards
ju juansolos 30 Aug, 2017
Answer
2 Likes
I have found a solution. I hope it is the right method.

I creat a logic php event above email event called myphp :
if($this->data["myfield"]  =='myvalue'): $hop='my text';
else : $hop='my other text';
endif;
return $hop;


and in email event
i call it with {var:myphp}

Seems correct

Regards
Max_admin Max_admin 31 Aug, 2017
Hi Juan,

Correct!

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
ju juansolos 25 Sep, 2017
Hi,
ok that works but if i have 100fields, i have to creat 100 logic php even to check if the var is empty?

Maybe another easy method?

Regards
Max_admin Max_admin 29 Sep, 2017
1 Likes
Hi Juan,

There is a way, by passing dynamic parameters to the php function, define the PHP function before the email like this:

if($this->data($this->get("pname"))){
echo $this->get("plabel");
}

Then in your email:

{fn:myphp$pname=field1&plabel=field1}
{fn:myphp$pname=field2&plabel=field2}


And the next update should have a new feature which can provide an easier solution.

Best 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.