Print the table based on the selected option of a radio element

125 Views Asked by At

I have a radio element with three options (Normal, Time Sensitive, and Hold For Pick-Up). Every time an user clicks an option, an unique table element for the option (for user to fill information) will pop up automatically. Finally, I would like to print all the submitted data to PDF attachment.

As I write the twig code for it, I am stuck in the part where I want to print the table that belongs to the selected option

{# choose_your_shipping_option: radio's key  #}
{# Normal: option text #}
{% if webform_token('[webform_submission:values:choose_your_shipping_option]') == "Normal" %}
<table>
    <tr>
        <th>Shipping Address:</th>
        <th>Acct #</th>
    </tr>
    <tr>
        <td rowspan="3">[webform_submission:values:shipping_address]</td>
        <td>[webform_submission:values:id_num]</td>
    </tr>
    <tr>
        <th>Phone</th>
    </tr>
    <tr>
        <td>
            [webform_submission:values:phone]
        </td>
    </tr>
</table>
{% elseif webform_token('[webform_submission:values:choose_your_shipping_option]') == "Time Sensitive" %}

<table>
    <tr>
        <th>Delivery Date</th>
        <td>[webform_submission:values:time_sensitive_01_delivery_date]</td>
        <th>Must Have Street Address (No PO Box)</th>
    </tr>
    <tr>
        <th colspan="2">Shipping Address:</th>
        <th>Acct #</th>
    </tr>
    <tr>
        <td colspan="2" rowspan="3" style="text-align: center;">[webform_submission:values:shipping_address_2]</td>
        <td>[webform_submission:values:id_num]</td>
    </tr>
    <tr>
        <th>Phone</th>
    </tr>
    <tr>
        <td>
            [webform_submission:values:phone_2]
        </td>
    </tr>
</table>
{% elseif webform_token('[webform_submission:values:choose_your_shipping_option]') == "Hold For Pick-Up" %}

<table>
    <tr>
        <th>Will be picked up by</th>
        <th>Pick-up Date:</th>
    </tr>
    <tr>
        <td>[webform_submission:values:pick_up_01_picked_up_by]</td>
        <td>[webform_submission:values:pick_up_01_pick_up_date]</td>
    </tr>
    <tr>
        <th>Pick-up Location</th>
        <th>Pick-up Time</th>
    </tr>
    <tr>
        <td>[webform_submission:values:location]</td>
        <td>[webform_submission:values:time]</td>
    </tr>
</table>

{% endif %}

It would ruin the pdf template when I use webform_token. Is there a correct way to print only the one that's filled by the user?

0

There are 0 best solutions below