HTML section and if statements

Conditionally display form data in a ChronoForms confirmation page.

Overview

The issue occurs when trying to show a specific field's data only when a related dropdown has a certain value, using an incorrect PHP variable reference.
Use the correct `$this->data()` method within a PHP `if` statement in the HTML section to check the dropdown value and conditionally echo the table row containing the dependent field's data placeholder.

Answered
ChronoForms v6
to tomaszciti 21 Feb, 2020
Hi

I have multi page form - the last page is a confirmation page (page 4 of the form) where I print the data entered / selected on previous pages.

I have one text field conditional on the dropdown value. The dropdown is called "packs_required" with the following values:

1 Pack (Free P&P)=1 Pack (Free P&P)
Multiple Packs=Multiple Packs

When "Multiple Packs" is selected the text field is shown called "no_of_multiple_packs". This is all working.

Now on the confirmation page I'd like to print the data in an HTML section e.g.
<table>
<tr><td><strong>Packs Required: </strong></td><td>{data:packs_required}</td></tr>
<tr><td><strong>No of Multiple Packs: </strong></td><td>{data:no_of_multiple_packs}</td></tr>
</table>

This prints the data fine but I'd like to print the value of "no_of_multiple_packs" if the value of "packs_required" is only "Multiple Packs".
So I need a condition in an HTML section...Can I add one?

So far I have tried:
<table>
<tr><td><strong>Packs Required: </strong></td><td>{data:packs_required}</td></tr>
<?php
if ( $form->data['if packs_required'] == 'Multiple Packs' ) {
echo "<tr><td><strong>No of Multiple Packs: </strong></td><td>{data:no_of_multiple_packs}</td></tr>";}
?>
</table>
But the code above does not work for some reason...
to tomaszciti 21 Feb, 2020
<?php
if ( $this->data('no_of_multiple_packs') != "" )
{
echo "<tr><td><strong>No of Multiple Packs: </strong></td><td>{data:no_of_multiple_packs}</td></tr>";
}
?>
It's not what I need but this prints only when "no_of_multiple_packs" field is not empty so it looks like I can use PHP in HTML section. Now I just need to work out how to print only when 'if packs_required' value is = 'Multiple Packs'
to tomaszciti 21 Feb, 2020
Answer
This seems to work fine:
<?php
if ( $this->data('packs_required') == 'Multiple Packs' )
{
echo "<tr><td><strong>No of Multiple Packs: </strong></td><td>{data:no_of_multiple_packs}</td></tr>";
}
?>
This topic is locked and no more replies can be posted.