Problem Description
Please help me, does anybody know where I am going wrong, this is starting to annoy me.
I am using moodle 2.2 and quick forms, it saves to the database on submit but then returns to the form with error.
mysqli::real_escape_string() expects parameter 1 to be string, array given in <b>/$root/lib/dml/mysqli_native_moodle_database.php</b>
I am also trying to upload a doc in the form to the course context to massively struggling.
<?php
require_once("../../config.php");
$courseid=2;
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
error('Site is misconfigured');
}
$context = get_context_instance(CONTEXT_COURSE, $course->id);
require_login($courseid);
/// Otherwise fill and print the form.
$thetitle = 'Edit Vacancy';
$PAGE->set_title($thetitle);
$PAGE->set_heading($thetitle);
$PAGE->set_pagelayout('base');
$PAGE->navbar->add($thetitle);
$PAGE->set_url('/systems/phones/index.php');
require_once('create_form.php');
//Instantiate simplehtml_form
$mform = new simplehtml_form();
//Form processing and displaying is done here
if ($mform->is_cancelled()) {
//Handle form cancel operation, if cancel button is present on form
redirect('view.php');
} else if ($fromform = $mform->get_data()) {
//In this case you process validated data. $mform->get_data() returns data posted in form.
$toform = new stdClass();
$toform->title = $fromform->title;
$toform->refno = $fromform->refno;
$toform->closedate = $fromform->closedate;
$toform->hours = $fromform->hours;
$options = array('subdirs'=>1, 'maxbytes'=>$CFG->userquota, 'maxfiles'=>-1, 'accepted_types'=>'*', 'return_types'=>FILE_INTERNAL);
$toform = file_postupdate_standard_filemanager($toform, 'files', $options, $context, 'user', 'private', 0);
$DB->insert_record('systems_jobs', $toform);
} else {
// this branch is executed if the form is submitted but the data doesn't validate and the form should be redisplayed
// or on the first display of the form.
//Set default data (if any)
$mform->set_data();
//displays the form
}
echo $OUTPUT->header();
$mform->display();
echo $OUTPUT->footer();
?>
WITH MY FORM:
<?php
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
require_once($CFG->libdir.'/formslib.php');
class simplehtml_fo...
AI-Generated Solution
Powered by LMSouq AI · GPT-4.1-mini
Analyzing problem and generating solution…
Was this solution helpful?