Forums

HTML section and if statements

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...
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'
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.