• Resolved josephquenta

    (@josephquenta)


    Hello.

    About your answer on other post:

    add_filter(“gfexcel_field_disable”, function ($disabled, $field) {
    $field_ids_to_disable = array(1, 2);
    if (in_array($field[‘id’], $field_ids_to_disable)) {
    $disabled = true;
    }
    return $disabled;
    }, 10, 2);

    Hpw to make that on specific form?

    Thanks for your help!

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

    (@doekenorg)

    Hi @josephquent, your question showed me something I forgot, so thanks for that ?? Normally I add the formID as an extra filter param, this time I forgot… oops. (will add this in the next version).

    But you can still make this work by updating to something like this:

    add_filter("gfexcel_field_disable", function ($disabled, $field) {
        if($field['formID'] !== '1')  return $disabled; //this way, only the form with id 1 is targeted (this is the defensive programming method)
    
        $field_ids_to_disable = array(1, 2);
        if (in_array($field[‘id’], $field_ids_to_disable)) {
            $disabled = true;
        }
    
        return $disabled;
    }, 10, 2);
    Thread Starter josephquenta

    (@josephquenta)

    Hello!

    I don’t know why not work that script,

    but with this, it worked!

    add_filter(“gfexcel_field_disable”, function ($disabled, $field) {

    $field_ids_to_disable = array(4, 37);
    if (in_array($field[‘id’], $field_ids_to_disable)) {
    if($field[‘formId’] == 11){
    $disabled = true;
    }
    else {
    $disabled = false;
    }
    }

    return $disabled;
    }, 10, 2);

    thanks for all!!

    Plugin Author Doeke Norg

    (@doekenorg)

    Awesome! Glad it worked out!

    Thanks for the great plugin!

    However, I am not very good with php. What values do I put in the array if want all entries in the second column not exported? And what does the 10,2 in the bottom stand for?

    Thanks!
    Jesper

    Plugin Author Doeke Norg

    (@doekenorg)

    Hi @jhultqvist,

    It depends a bit on what the form id is (you can see that in de the url when you are editing the form), and the field id (this is the id in the header of the field when editing). Say your form id is 2, and the field id is 3, the code would be:

    
    add_filter("gfexcel_field_disable", function ($disabled, $field) {
        if($field['formID'] != 2)  return $disabled; 
    
        $field_ids_to_disable = array(3); // add al the field id's for the form you want to disable here, comma seperated
        if (in_array($field[‘id’], $field_ids_to_disable)) {
            $disabled = true;
        }
    
        return $disabled;
    }, 10, 2);
    

    The 10 in 10, 2 stand for the priority this filter has, 10 is quite standard. And the 2 actually stands for the amount of arguments you want to give to the callback function. By default the add_filter method only gives the first argument to the function, but because we also need the field info, so we need to be explicit about the number of arguments. If we didn’t give the 2, you’d only be able to read the $disabled value, and not the $field.

    Hope this helps you out.

    Thanks Doeke for the explainer! I can’t get it to work though.

    I want form 3, field 1 not to be exported and used this code:

    add_filter(“gfexcel_field_disable”, function ($disabled, $field) {
    if($field[‘formID’] != 3) return $disabled;

    $field_ids_to_disable = array(1); // add al the field id’s for the form you want to disable here, comma seperated
    if (in_array($field[‘id’], $field_ids_to_disable)) {
    $disabled = true;
    }

    return $disabled;
    }, 10, 2);

    Nothing happens, as in: the field is still included in the export. I tried josephquenta’s syntax as well. Same result though. I am using your filter for the meta data and that is working.

    Kind regards,
    Jesper

    Plugin Author Doeke Norg

    (@doekenorg)

    It might be ‘formId’. Not sure. But if you can hold on for a few days. I’m currently finishing up version 1.4 which has this as checkboxes on he settingspage. Way easier! I’ll let you know when it is out!

    Great! I’ll wait!

    Jesper

    Plugin Author Doeke Norg

    (@doekenorg)

    Hi @jhultqvist,

    Can’t stand it if something doesn’t work. So here is the code. This SHOULD work. I’ve tested it on form 3, field 1 ??

    add_filter("gfexcel_field_disable", function ($disabled, $field) {
    
        if($field['formId'] != 3)  return $disabled;
    
        $field_ids_to_disable = array(1); // add al the field id's for the form you want to disable here, comma seperated
        if (in_array($field['id'], $field_ids_to_disable)) {
            $disabled = true;
        }
    
        return $disabled;
    }, 10, 2);

    I think something went wrong with the quotes around ‘id’. And it should indeed be ‘formId’. So the code above should definitely work.

    Thanks @doekenorg !
    That worked like a charm! ??

    Jesper

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Exclude fields in export file in specific form’ is closed to new replies.