Forums

Add conditions on {field_value} inside the Email Template?

chrbar 26 Feb, 2013
Hello,

I've installed Chronoforms V4 RC3.5.2 on Joomla 2.5.8.
I'm a Chronoforms newbie 😶

I would like to know if it's possible to add/insert some conditions on {field_value} inside the Email Template (or inside the "Show Thanks Message")?

For example, I've built a Recommendation Form for my Web page (it runs correctly) and I would like to insert the Name of the Sender inside the email sent to the Recipient:
<p>{sender_name} invite you to see this Web page</p>

But because the "sender_name" field is not required, I would like to change the sentence to:
<p>You're invited to see this Web page</p>
if the "sender_name" field is empty.

Is it possible to add conditions inside the Email Template (and inside the "Show Thanks Message")?

Thanks a lot for you help🙂
Chris
chrbar 28 Feb, 2013
Hello🙂
Nobody have any idea about my post?
GreyHead 01 Mar, 2013
Hi chrbar,

You can add PHP to the Email template to do this, but not to the Thank You Message action :-(

The simplest solution is to add a Custom Code action, drag it up before the other two actions and add code like this:
<?php
if ( isset($form->data['sender_name']) && $form->data['sender_name'] ) {
  $form->data['invite'] = $form->data['sender_name']." invites you to see this Web page.";
} else {
  $form->data['invite'] =  "You're invited to see this Web page.";
}
?>
Then use {invite} in the Email and Thank You page.

Bob
chrbar 02 Mar, 2013
It runs perfectly!
Thanks a lot Bob🙂
chrbar 02 Mar, 2013
Hello,

I'm not PHP coder... I have to learn it, it'll open a lot of doors to me!

Is it possible to update the code of Bob to change the condition to:
if a field value is X (a specific value)
then
$form->data['invite'] will be A
else
$form->data['invite'] will be B

Thanks for your help🙂
GreyHead 03 Mar, 2013
Hi chrbar,

Something like this:
<?php
if ( isset($form->data['sender_name']) && $form->data['sender_name'] ) {
  if ( $form->data['sender_name'] == 'Some Name' ) {
    $form->data['invite'] = "XXX invites you to see this Web page.";
  } else {
    $form->data['invite'] = $form->data['sender_name']." invites you to see this Web page.";
  }
} else {
  $form->data['invite'] =  "You're invited to see this Web page.";
}
?>

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