• Resolved markhewes

    (@markhewes)


    Hi,

    Is there a way to automatically exclude fields that don’t have any user input? Specifically, I have many forms with multiple HTML blocks. When I export the spreadsheet, each HTML block has its own column. I know I can edit the settings for each form to exclude those fields manually, but would love it if there was a way to exclude them automatically.

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Doeke Norg

    (@doekenorg)

    Hi @markhewes,

    Fields can be disabled by default. Sections are excluded by default when you enable that setting on the main settings page.

    I’ll try to provide a hook you can add to your functions.php which disables all html fields later today.

    Plugin Author Doeke Norg

    (@doekenorg)

    This should help you out:

    // Handle HTML Blocks like section fields, and disable them if the setting is true.
    add_filter('gfexcel_transformer_fields', function ($fields) {
        if (!array_key_exists('html', $fields)) {
            $fields['html'] = 'GFExcel\Field\SectionField';
        }
    
        return $fields;
    });

    Be sure you have the sections turned off (this is the default settings).

    Hope this helps you out.

    Thread Starter markhewes

    (@markhewes)

    Perfect! Thanks so much. Could I also adapt this to exclude other field types? Credit Card, for example?

    Plugin Author Doeke Norg

    (@doekenorg)

    Yes this should be possible. in that case it would be:

    add_filter('gfexcel_transformer_fields', function ($fields) {
        if (!array_key_exists('html', $fields)) {
            $fields['html'] = 'GFExcel\Field\SectionField';
        }
        if (!array_key_exists('creditcard', $fields)) {
            $fields['creditcard'] = 'GFExcel\Field\SectionField';
        }
    
        return $fields;
    });

    But repeating those lines for even more can be a bit annoying, so something like this would be even better:

    // Disable these field types if sections are invisible.
    add_filter('gfexcel_transformer_fields', function ($fields) {
        // add types to this array
        $disable_field_types = [
            'html',
            'creditcard',
        ];
    
        foreach ($disable_field_types as $type) {
            if (!array_key_exists($type, $fields)) {
                $fields[$type] = 'GFExcel\Field\SectionField';
            }
        }
    
        return $fields;
    });

    It is possible I’m updating these field types in the future, thats why I added the array_key_exists check. If I provide a specific field class of my own, that will take precedence. But for now I have no such ideas ??

    Thread Starter markhewes

    (@markhewes)

    Thanks!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Automatically exclude HTML block fields’ is closed to new replies.