Must specify course id, short name or idnumber

Must specify course id, short name or idnumber

by Abhishek Pawar -
Number of replies: 1

Dear All,

block_attendance.php

<?php

defined('MOODLE_INTERNAL') || die();

require_once('attendance_form.php');

class block_getattendance extends block_base {

public function init() {

$this->title = get_string('pluginname', 'block_getattendance');

}

public function get_content(){

$this->content = new stdClass();

$this->content->text = '';

$mform = new attendance_form();

if ($mform->is_cancelled()) {

} else if ($fromform = $mform->get_data()) {

} else {

$mform->set_data($toform);

$this->content->text = $mform->render(); 

}

return $this->content;

}

public function instance_allow_multiple() {

return true;

}

function has_config() { return true; }          

}


attendance_form.php

<?php
require_once("$CFG->libdir/formslib.php");
require_once('../config.php');
class attendance_form extends moodleform {
function definition() {
global $CFG;
$mform =& $this->_form;
$mform->addElement('date_selector', 'assesstimefinish', get_string('to'));
$mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
$this->add_action_buttons();
}
}


Attachment error.png
Average of ratings: -
In reply to Abhishek Pawar

Re: Must specify course id, short name or idnumber

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Was there a question in there?

Assuming you wanted some help in stopping the error message - you have a form on the page, which does not include a hidden 'id' field. When the form is submitted it sends the user back to the 'course/view.php' page, but, due to the lack of an 'id' param in the form data, the page does not know which course you want to display, so it gives an error.

Add the missing hidden 'id' field and make sure it has the same value as the current course and the page should submit.

Whilst you are at it, get rid of the '&' symbol in the form definition - PHP 4 support was dropped from Moodle a long time ago, so there is no need to try to write PHP 4 compatible code any more.


Average of ratings: Useful (1)