Trabla: Moodle: Course creation form - add field yes/no
Solving:
1. Create database column
ALTER TABLE mdl_course ADD COLUMN myfield smallint DEFAULT 0; -- default NO
UPDATE mdl_course SET myfield = 0;
ALTER TABLE mdl_course ALTER COLUMN myfield SET NOT NULL;
2. Modify course creation form .php script
/moodle/course/edit_form.php
$mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"');
$mform->addHelpButton('idnumber', 'idnumbercourse');
$mform->setType('idnumber', PARAM_RAW);
if (!empty($course->id) and !has_capability('moodle/course:changeidnumber', $coursecontext)) {
$mform->hardFreeze('idnumber');
$mform->setConstants('idnumber', $course->idnumber);
}
//Start: This is my field!!!
$mform->addElement('selectyesno', 'myfield ', "This is my course yes/no field" );
$mform->setDefault('myfield ', 0); //default NO
//End: This is my field!!!
$mform->addElement('editor','summary_editor', get_string('coursesummary'), null, $editoroptions);
$mform->addHelpButton('summary_editor', 'coursesummary');
$mform->setType('summary_editor', PARAM_RAW);
Result:
No comments:
Post a Comment