• Resolved liaos

    (@liaos)


    Hi, I am trying to export form entries as excel files and need to have custom field names for all questions.

    Most of these can be done by using “admin field”, however, for survey which may have 20+ yes/no questions, the excel file shows the entire long question as the field label.

    Is there any way I can create/match custom field label with each question before exporting form entries to excel file? especially for these long multiple survey questions?

    Thank you again for all your help!!!

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

    (@doekenorg)

    Hi @liaos,

    The docs has a pretty extensive explanation on changing labels. I think the answer is in there. If not please let me know.

    https://gfexcel.doeken.org/docs/changing-labels/

    Thread Starter liaos

    (@liaos)

    Hi Doeke,
    As usual, thanks for the lightening-fast reply. ^_^ And thanks for the link provided.

    In the documentation, it shows how to change label by identifying Field ID.
    However, when using likert Survey, it may have 10 Yes/No questiosn for one survey that shows only one field ID.
    Here is the html from the likert survey example:
    <table class=”gsurvey-likert” id=”input_11″><tr>
    <td data-label=”” class=”gsurvey-likert-row-label”>Q1</td>
    <td data-label=”” class=”gsurvey-likert-row-label”>Q2</td>
    <td data-label=”” class=”gsurvey-likert-row-label”>Q3</td>
    <td data-label=”” class=”gsurvey-likert-row-label”>Q4</td>
    <td data-label=”” class=”gsurvey-likert-row-label”>Q5</td>
    </tr></table>

    Sometimes, each survey may have 10+ questions, so is there any possible way to map field labels so in the excel file for surveyA, the labels can be customized to something like these?
    Q1 = SurveyA_Q1
    Q2 = SurveyA_Q2
    Q3 = SurveyA_Q3
    Q4 = SurveyA_Q4
    Q5 = SurveyA_Q5

    I am hoping that it is still possible.

    Plugin Author Doeke Norg

    (@doekenorg)

    Hi @liaos,

    Sorry i didn’t realise you ment a plug in. I don’t own that specific plugin, so it’s hard to say. If you can provide me with the plugin on [email protected] I’d love to take look.

    Plugin Author Doeke Norg

    (@doekenorg)

    Hi @liaos,

    Luckily this was way easier than I thought. Add the following code to your functions.php and adjust were needed.

    // This is the likert field for form 6, field id 1.
    add_filter('gfexcel_field_label_likert_6_1', function ($label, $field) {
        // update / add values here
        // If you only need to update the fourth field, remove the rest and only add:
        // '4' => 'your value',
        $labels = [
            '1' => 'label1',
            '2' => 'label2',
            '3' => 'label3',
        ];
    
        // leave this as is. 
        foreach ($field->get_entry_inputs() as $input) {
            if ($input['label'] === $label && $parts = explode('.', $input['id'])) {
                if (isset($labels[$parts[1]])) {
                    // overwrite the label
                    return $labels[$parts[1]];
                }
            }
        }
    
        // use the original label
        return $label;
    }, 10, 2)
    • This reply was modified 5 years, 9 months ago by Doeke Norg. Reason: formatting
    Plugin Author Doeke Norg

    (@doekenorg)

    More contact behind the scenes; bottom line: this code fixes the question, for other interested people ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘custom field label for survey questions’ is closed to new replies.