<?php

function populate_note_comment_based_on_rating($form)
{


	if ($form['id'] != 24) return;



	foreach ($form['fields'] as $key => $field) {
		if ($field->type !== "homegrade-rating" && $field->type !== "classic-rating") continue;

		$user_rating = rgpost("input_{$field->id}");

		$nextHiddenLabelField = $form["fields"][$key + 1] ?? null;
		$stringified_information_accessibility_rating = isset($field["choices"][$user_rating - 1]['text']) ? $field["choices"][$user_rating - 1]['text'] : '';


		if (!$nextHiddenLabelField || $nextHiddenLabelField->type !== "hidden" || !$stringified_information_accessibility_rating) continue;


		$_POST["input_{$nextHiddenLabelField->id}"] = $stringified_information_accessibility_rating;
	}
}
add_action('gform_pre_submission', 'populate_note_comment_based_on_rating');
