Forums

Conditional PHP logic in thank you message

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?
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
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?
petersen 09 Sep, 2014
Also, how do you get the custom action to display something after submit?
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
petersen 09 Sep, 2014
Thanks Bob. 😀
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
petersen 09 Sep, 2014
Correct, I was being a doofus.
This topic is locked and no more replies can be posted.