Module

Archived
Forum
(read-only)

ProForm Drag and Drop Form Builder

ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Isaac Raway

     

[Resolved] Conditional fields and notifications

Support (Resolved)

Jerome
Jerome

Hey Isaac,

I have a form that has a bunch of conditional fields. All of them work perfectly but when the user submits their form, all the fields show up in my email..even the ones that they didn’t select, (lists, texts, radio buttons etc.). How do I stop that from being sent. Tried editing my template with the below;

{fields}
    {if field_type 
!= "hidden"}
        {field_label}
{field_value}
    {
/if}
{
/fields} 

But they aren’t really hidden fields in that sense….or am I doing something wrong.

Please assist any way you can.

Thanks and have a great weekend.

MetaSushi
# 1
Developer
MetaSushi

Usually in this case I recommend going one of two routes:

Option 1. Add additional checks to {field_value} to make sure it is not blank and/or not a default value.

{fields}
    {if field_type 
!= "hidden"}
        {if field_value 
!= "" and field_value != "default"}
            {field_label}
{field_value}
        {
/if}
    {
/if}
{
/fields} 

Option 2. Use the alternative syntax to access data directly and create conditionals that match the conditional fields rules, along with a more complete layout such as:

{if value:conditional_field == 'option1'}
<hr>
    
Field 1:  {value:dependent_field1}<br>
    
Field 2{value:dependent_field2}<br>
{/if}

{if value
:conditional_field2 == 'something'}
<hr>
    
Field 3:  {value:dependent_field3}<br>
    
Field 4{value:dependent_field4}<br>
{/if} 

This way you have complete control over the way the data is presented.

Jerome
# 2
Jerome

Hey Isaac,

Thanks for this…however something weird is happening. I can’t seem to use any of the operators for my if statement;

{fields}
        {if field_value 
!="Please Select One" OR field_value !=""}
            
<b>{field_label}</b>: {field_value}<br />
        
{/if}

{
/fields} 

The above doesn’t work, however if I take out one of the conditions, it will work. Tried using “||” and “OR” but none seem to work and I don’t know why.

MetaSushi
# 3
Developer
MetaSushi

I believe you want AND in this case, not OR. With your OR clause as written, any value would match.

Also try using quoted strings around the variables:

{fields}
        {if 
"{field_value}" !="Please Select One" AND "{field_value}" !=""}
            
<b>{field_label}</b>: {field_value}<br />
        
{/if}

{
/fields} 

 

Jerome
# 4
Jerome

Thanks Isaac, it worked with the quoted strings. Weird that it wouldn’t work without it.