• Resolved jokewouters

    (@jokewouters)


    Hi Doenke,

    First of all, thank you for this great plugin. This is exactly what I needed!

    There’s only one thing that’s not exporting correctly for me. Can you check is there’s an easy way to fix this?

    I have a lot of name fields with sub label ‘First’ and ‘Last’. On these fields I use a custom Admin Field Label. I’ve already found some code from you to make sure these labels are used and that works great. Only thing I need now is the (First) and (Last) part to apear too.

    For example I have a label “Present_name (First)”. When I export with the generated URL, the label becomes “Presenter_name” without the (First) or (Last) part. As we already built an offline tool that uses that exact header, I need the export to include that part.

    Is it possible to add these in any way?

    Coding I already used from you:

    /**
    * Concatenate name fields on a single line.
    */
    add_filter(‘gfexcel_field_value_name’, static function (string $value) {
    return str_replace(“\n”, ‘ ‘, $value);
    });

    /**
    * Labels bij export
    */
    add_filter(‘gfexcel_field_label’,function($label,$field) {
    if($field->adminLabel) {
    return $field->adminLabel;
    }
    return $label;
    },10,2);

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

    (@doekenorg)

    Hoi Joke,

    Dit is vast mogelijk. Ik probeer hier vanavond even op terug te komen.

    Plugin Author Doeke Norg

    (@doekenorg)

    Hi Joke,

    As promised, you can just add this code to your functions.php.

    Hope this helps you out.

    // Adds the original field name to a name-field sub label.
    add_filter('gfexcel_field_label_name', static function ($sub_label, \GF_Field $field) {
        $field_label = $field->get_field_label(false, '');
    
        return sprintf('%s (%s)', $field_label, $sub_label); // exports as: name (first).
    }, 10, 2);
    Thread Starter jokewouters

    (@jokewouters)

    Hi Doeke,

    Thanks for your quick response. Of moet ik eerder bedankt zeggen? ??
    Unfortunately this is not working as expected. Now I get a mix of labels. I mostly use a custom admin field label. This is now showing between the brackets (). Not the (First) or (Last) sub label.

    For example our first name field.

    Field Label = Your name
    Admin Field Label = Presenter_name

    Manual export from GF = Presenter_name (First) –> and this is what I need
    Your plugin export = Your name (Presenter_name)

    Any ideas?

    Plugin Author Doeke Norg

    (@doekenorg)

    Hi Joke,

    Helemaal aan jou ?? Ik doe het graag in het engels voor het geval iemand anders dit probleem ook heeft.

    This should do the trick in that case.

    // Adds the original field name to a name-field sub label.
    add_filter('gfexcel_field_label_name', static function ($input_label, \GF_Field $field) {
        $field_label = !empty($field->adminLabel) ? $field->adminLabel : $field->label;
    
        return sprintf('%s (%s)', $field_label, $input_label);
    }, 10, 2);
    

    This will be applied to all name fields. I can’t mimick the exact export of gravity forms (just yet) but this might be easier in the future.

    Thread Starter jokewouters

    (@jokewouters)

    Okay, we’re almost there. It’s still not using the original (First) and (Last) sub labels.

    Now I get this: Presenter_name (Presenter_name)

    Plugin Author Doeke Norg

    (@doekenorg)

    Ahh, this is because you already have the other gfexcel_field_label hook. I forgot. You can remove that one, and replace it with this:

    // Admin labels on export.
    add_filter('gfexcel_field_label', static function ($input_label, \GF_Field $field) {
        $field_label = !empty($field->adminLabel) ? $field->adminLabel : $field->label;
        if ($field->get_input_type() !== 'name') {
            return $field_label;
        }
        
        // Adds the original field name to a name-field sub label.
        return sprintf('%s (%s)', $field_label, $input_label);
    }, 10, 2);

    So I’ve essentially updated the previous hook you had, to fix name fields only.

    Hope this is the one ??

    Thread Starter jokewouters

    (@jokewouters)

    BINGO! Works perfect now.

    Thank you very much ??

    Plugin Author Doeke Norg

    (@doekenorg)

    Ok, just one more. This will be future proof if you have any other field types that need the same treatment.

    // Adds the original field name to a field sub label.
    add_filter('gfexcel_field_label', static function ($input_label, \GF_Field $field) {
        $field_label = !empty($field->adminLabel) ? $field->adminLabel : $field->label;
        if (!$field->get_entry_inputs()) {
            return $field_label;
        }
    
        return sprintf('%s (%s)', $field_label, $input_label);
    }, 10, 2);

    So in stead of just listening for name fields, this will just check if the field has subfields, and apply the same structure to that. Your choice if you want to use it .

    Glad it worked out for now.

    Fijne avond.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Sub label (First) and (Last) not visible in export’ is closed to new replies.