PHP in Email Template

rstevens 18 Mar, 2013
I have an email template that sends me data from the form, but when I add some PHP, the data is not sent, even though the debugger shows the array of information from the form...

{fname} {lname}<br>
<?php
if (isset($form->data['company']) {
echo "$form->data['company']";
}
?>

Here is the debugger array...

Array
(
[option] => com_chronoforms
[tmpl] => component
[chronoform] => Contact3
[event] => submit
[Itemid] =>
[fname] => Roger
[lname] => Stevens
[company] => Stevens & Associates, Inc.

But the debugger also shows no data in the body of the email...

Body


Submitted by 24.123.21.131

Can anyone tell me why the addition of PHP does this? The template works fine without it.
GreyHead 18 Mar, 2013
Hi rstevens,

I can see two errors in the PHP :-(

But the bigger problem is that most likely $form->data['company'] is always set so it won't do anything.

What do you want to achieve here?

Bob
rstevens 18 Mar, 2013
I fixed the PHP errors...

<?php
if( isset($form->data['business_name']) && $form->data['business_name'] != '' ) {
echo 'Business Name: '.$form->data['business_name'].'<br>';
}
?>

I just want the business name, if it exists to be printed (echoed) in the email to me.
GreyHead 18 Mar, 2013
Hi rstevens,

Then just Business Name: {business_name}<br /> should do it.

Bob
rstevens 18 Mar, 2013
Thanks. Maybe I am not doing this correctly.

Can you tell me the difference between putting custom code action under the events tab, and putting a custom code element under the preview tab.?
GreyHead 18 Mar, 2013
Hi rstevens,

Being picky here to make it clearer; you can't put a Custom Code *action* into the Preview box. Only Elements go into the Preview box. You can put a Custom Element element there.

Actions go into events on the Events tab.

You can add a Custom Code action into the On Load or the On Submit event (or any other event that you've added to your form).

Custom Code actions in the On Load event are typically used to do something before the form loads; those in the On Submit event are used to do something after the form submits.

You can add PHP to the Email template directly provided that the Rich Text Editor is turned off. I prefer, and recommend, that you do any data processing of the submitted data in a Custom Code action before the Email action; add the result into the $form->data array and then use the {input_name} syntax in the email template itself. This keeps the code cleaner and avoids any problems if the Rich Text Editor is turned on in some future edit.

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