require_once("$CFG->libdir/formslib.php");
class block_add_edit_form extends moodleform {
public function definition()
{
global $CFG,$DB;
$mform = $this->_form;
$mform->addElement('text', 'id');
$mform->setType('id', PARAM_INT);
$mform->addElement('editor', 'attachment',get_string('file', 'block_add'),);
$mform->setType('attachment', PARAM_RAW);
$this->add_action_buttons();
}
function validation($data, $files) {
return array();
}
This is my form where i assigning values, down below is the code where i want insert but getting this error
Coding error detected, it must be fixed by a programmer: Invalid context id specified context::instance_by_id() Debug info: Error code: codingerror Stack trace:
line 5346 of \lib\accesslib.php: coding_exception thrown line 1776 of \lib\blocklib.php: call to context::instance_by_id() line 1478 of \lib\blocklib.php: call to block_manager->process_url_edit() line 1645 of \lib\pagelib.php: call to block_manager->process_url_actions() line 1110 of \lib\pagelib.php: call to moodle_page->starting_output() line 1391 of \lib\outputrenderers.php: call to moodle_page->set_state() line 179 of \my\index.php: call to core_renderer->header()
require_once (__DIR__ . '/../../config.php');
require_once('edit_form.php');
$mform = new block_add_edit_form();
global $DB;
if ($mform->is_cancelled()) {
print_r("1");
}else if ($fromform = $mform->get_data()) {
var_dump($mform->get_data());
$record = new stdClass();
$record->id = $fromform->id;
$record->attachment = $fromform->attachment;
$DB->insert_record('image', $record);
}
echo $OUTPUT->header();
$mform->display();
echo $OUTPUT->footer();