Add fields to Create New Course page - some work some don't

Add fields to Create New Course page - some work some don't

by Leslie Huang -
Number of replies: 4

 

I am trying to add few new fields to Create Course page, also added columns to mdl_course table, but can't figure it out what was wrong as some of them work but some don't.  Does any one has the experience to share?  Thanks in advance.

On the course/edit_form.php:

A. Added below and works: (course create page, after adding field designid to course table,  'designid' get to be saved to table )

1)

$designlist = array();

$designs = $DB->get_records_sql('select * from mdl_course_designs where dropdown = 1 order by name');

$designlist[0] = 'Select One';

foreach($designs as $d) {

            $designlist[$d->id] = $d->name; }

$mform->addElement('select', 'designid', 'Design', $designlist);

2)

$mform->addElement('selectyesno', 'is_design', 'Is a Design Template');


B. However, added below similar 3 things but not working ('maxstudents', 'total_ceus',  'provider' are not saved to table):

1)

$studentrange = range(0, 300);

$mform->addElement('select', 'maxstudents', 'Max Students', $studentrange);

2)

$mform->addElement('text', 'total_ceus', 'Total Number of Hours/CEUs '); $mform->setType('total_ceus', PARAM_FLOAT);

3)

       $providerlist = array();

        $providers = $DB->get_records_sql('select * from mdl_course_provider');

        $providerlist[0] = 'Select One';

        foreach($providers as $p) {

                $providerlist[$p->id] = $p->name;

        }

        $mform->addElement('select', 'provider', 'Provider', $providerlist);

 



Average of ratings: -
In reply to Leslie Huang

Re: Add fields to Create New Course page - some work some don't

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You don't want to go changing the course table and form directly - these are part of core Moodle and you could very easily make your Moodle installation incompatible with future versions and unable to upgrade.

One way to acheive this sort of thing in a clean and supported way would be through a Course Format plugin, using "course format options".

Average of ratings: Useful (1)
In reply to Mark Johnson

Re: Add fields to Create New Course page - some work some don't

by Leslie Huang -

Thanks Mark! We do have concerns about the future upgrade but didn't know the better way to achieve our needs.

I briefly went through the course format but not sure if I understand it correctly:  Do you mean within a new course format plugin, I can include those fields we need, and store them in the mdl_course_format_option table--each new field will be a new "name" and "value" pair for the coursed ?

In reply to Leslie Huang

Re: Add fields to Create New Course page - some work some don't

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

Yes - take a look at the way a format such as collapsed topics does it as a 'template'