LMSouq
moodle-core Open

Moodle moodleform::validation()

NE
Neeraj
1 month ago
3 views
Problem Description
In my custom plugin I am simply using three drop down and one text box. When I submit the form and `validation($data)` method is invoked I just get value of state drop down along with the textbox value. Value of other two drop downs is not returned. I am not sure what I am missing. Here is my code: if (!defined('MOODLE_INTERNAL')) { die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page } require_once($CFG->libdir.'/formslib.php'); class ohio_addconfiguration_form extends moodleform { // Define the form function definition() { $id = optional_param('id', 0, PARAM_INT); $countries = array(); $states = array(); $counties = array(); $cities = array(); $mform =& $this->_form; // Creating hidden variable id $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); // Creating header "Configuration" $mform->addElement('header', 'configuration', get_string('ohio', 'local_ohio')); /* Listing States */ $states_result = $this->get_states("", "1", "id, state_name", "state_name ASC"); if($states_result) { foreach($states_result as $key=>$state){ $states[$state->id] = $state->state_name; } } $states= count($states)?array(''=>get_string('select_state', 'local_ohio').'...') + $states :array(''=>get_string('select_state', 'local_ohio').'...'); $mform->addElement('select', 'state_id', get_string('select_state', 'local_ohio'), $states); $mform->addRule('state_id', get_string('required'), 'required', null, 'client'); $mform->setType('state_id', PARAM_INT); /* Listing Counties */ $counties= array(''=>get_string('select_county', 'local_ohio').'...'); $mform->addElement('select', 'county_id', get_string('select_county', 'local_ohio'), $counties); $mform->addRule('county_id', get_string('required'), 'required', null, 'client'); $mform->setType('county_id', PARAM_INT); /* Listing Cities */ $cities= array(''=>get_string('select_city', 'local_ohio').'...'); $mform->addElement('select', 'city_id', get_string('select_city', 'local_ohio'), $cities); $mform->addRule('city_id', get_string('required'), 'required', null, 'client'); $mform->setType('city_id', PARAM_INT);...

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