Conditional PHP logic in thank you message

How to add conditional PHP logic in a ChronoForms thank you message.

Overview

The issue occurs because the standard CF Thank You Message action does not support PHP code.
Use a Custom Code action instead, which allows PHP. Within the PHP tags, access form data using the $form->data array, and ensure any output is echoed or written in HTML.

Answered
pe petersen 09 Sep, 2014
Hi,

On the thankyou action page I'd like to include some conditional logic based on the value of a field.

<h2>Training</h2>
<?php if ($form->data['trainingrequired'] == 'Yes') {?>
<p>You have requested training.</p>
<?php } else { ?>
<p>You have not requested training.</p>
<?php } ?>
<p>If you wish to proceed with your quote, please contact us.</p>


This shows:
data['trainingrequired'] == 'Yes') {?>
in the form

How can I do something like this?
Gr GreyHead 09 Sep, 2014
1 Likes
Hi Petersen,

Yes you can do this but not in the Cfv4 Thank You Message action as it does' support PHP. Use a Custom Code action instead - it works in the same way but allows PHP.

Bob
pe petersen 09 Sep, 2014
Thanks Bob,

If you use the Custom Code - can you use the curly braces or do you need to use the form->data array?
pe petersen 09 Sep, 2014
Also, how do you get the custom action to display something after submit?
Gr GreyHead 09 Sep, 2014
Answer
1 Likes
Hi petersen,

You can use Curly Braces in HTML - but not in PHP. If you are inside the <?php . . . ?> tags you have to use $form->data['input_name'] Here's a demo example including both syntaxes:
<p>Hi {first_name},</p>
<?php
if ($form->data['trainingrequired'] == 'Yes') {
   echo "<p>You have requested {$form->data['training_type']} training.</p>";
} else { 
?>
<p>You have not requested {training_type} training.</p>
<?php
 } 
?>
<p>If you wish to proceed with your quote, please contact us.</p>

Bob
Gr GreyHead 09 Sep, 2014
Hi petersen,

Sorry, missed this one: Also, how do you get the custom action to display something after submit?

IIRC it should just display - needs to be echoed from PHP or HTML otherwise.

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