Php access to dropdown text

Access the displayed text of a selected dropdown option in PHP.

Overview

The dropdown only returns the option value, not the displayed text.
Create a PHP array that maps each option value to its corresponding display text, then use the selected value to retrieve the text from this array.

Answered
ChronoForms v7
am amitycol 06 Aug, 2025

Hi, I can easily access the value of a dynamically populated dropdown in PHP (example: $SelectedValue = $this->data("english_language_courses", 9);). How do I access the option text (displayed text) of the dropdown? Example: Selected dropdown item, which has a value of '24' displays 'General English Course'. '$SelectedValue' will return '24'. Now, if I need to assign 'General English Course' to '$SelectedText' what is the correct syntax?

Max_admin Max_admin 07 Aug, 2025
Answer
1 Likes

Hi amitycol

This is only possible if you have an array in your PHP code matching values to texts:

$texts = ["24" => "General English Course"];
$selected_text = $texts[$this->data("english_language_courses")];
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Post a Reply