I am trying to create a profile using a moodle form. In the questionnaire, the student first selects the Direction, and then the training profile. The values are taken from the database. <Select> with a profile should be generated based on the selected direction, i.e.
SELECT rp.id, rp.name FROM mdl_bsu_ref_profiles rp where specialityid = {$_GET['sclt']}
I did not find any standard methods for this implementation.
Try it with jQuery
function getValue() {Everything works in the interface (screen above), but when the form is submitted, the form element
var select = document.getElementById("id_napravlenie");
var sclt = select.value;
$.ajax({
url: "programma.php", //url страницы с запросом к БД
type: "GET",
data: "sclt="+sclt,
success: function(response) { //Данные отправлены успешно
$('#id_prof').html(response); // вставляем вернувшиеся данные в select
},
error: function(response) { // Данные не отправлены
$('#result_form').html('Ошибка. Данные не отправлены.');
}
});
}
$mform->addElement('select', 'prof', 'Планируемая программа подготовки ',$prof);
"prof" is not present at all in the object, i.e. once we changed the content of select '#id_prof' with jQuery, its data is not written to the DB. Database entry code:
if ($mform->is_cancelled()) {I would be grateful if someone can suggest or help. Sorry for the English, I used translate.google
redirect('/my/');
} else
if ($datanew = $mform->get_data()) {
if($datanew->id == 0) {
$DB->insert_record('asp_motivation', $datanew);
} else {
$DB->update_record('asp_motivation', $datanew);
}
$redirlink = "motivation.php";
redirect($redirlink, get_string('changessaved'), 0);
}
else {
$data = $DB->get_record_select('asp_motivation', "uid={$USER->id}");
$mform->set_data($data);
$mform->display();
}