Get Likert true value

Hi everybody, I’m trying to get the true value of Likert scales questions in php (from a gform_after_submission action) and so far the returned value is like “glikertcol1155f01cdf” etc. I’ve seen this is expected but I can’t understand how to get the true value, knowing I’ve activated scores calculation in my Likert questions from the form editor. Any help ?


add_action('gform_after_submission', 'recuperer_donnees_formulaire', 10, 2);

function recuperer_donnees_formulaire($entry, $form) {
    
    if ($form['id'] != 27) return;
    $total_points = 0;
   
	// Questions with Likert scale

$likert_ids = array(11, 17, 18, 19, 20, 21, 22, 23, 24);
foreach ($likert_ids as $id) {

    for ($sub_id = 1; $sub_id <= 5; $sub_id++) {
        $valeur_sub_champ = rgar($entry, $id . '.' . $sub_id);

        // Convert the sub-field value to a number
        $valeur_sub_champ_numerique = intval($valeur_sub_champ);

        // Add the sub-field value to the total score
        $total_points += $valeur_sub_champ_numerique;
    }
}
	  
}

I would like to avoid mapping the returned key values, like :

$likert_ids = array(11, 17, 18, 19, 20, 21, 22, 23, 24);
$likert_mapping = array(
    'glikertcol1155f01cdf' => 1,
    'glikertcol11fcc374ae' => 2,
    'glikertcol11358b8ecf' => 3,
    'glikertcol11dfa44d10' => 4,
    'glikertcol11c522b458' => 5
   
);

You can use the field object get_value_export method to get the field value using the column/row text (labels) instead of the unique values. Here is an example:

$field = GFAPI::get_field( $form_or_id, $field_or_input_id );
$text = $field->get_value_export( $entry, $field_or_input_id, true );

If by true value, you mean the score, you’ll need to use the following:

$field_score = gf_survey()->get_field_score( $field, $entry );
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.