LMSouq
moodle-core Open

Adding CSS class to form element in Moodle

AL
Aldo Paradiso
1 month ago
3 views
Problem Description
I create forms in Moodle by extending the moodle `moodleform` class and calling the `addElement()` or `createElement()` methods. For example, I create a select element this way: $mform->addElement('select', 'mySelect', 'Select title' , $list); Where `$mform` is a reference to the form, and `$list` is an associative array like: `$list = array('1'=>'one', '2'=>'two', '3'=>'three')`. The question is: Is there a way to add a CSS class associated with this or other form elements? I other words, I would like to programmatically add a class `myClass`, so that the HTML code looks like this: <select class="myClass"> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base