quickforms和moodle

quickforms和moodle,moodle,quickform,Moodle,Quickform,请帮帮我,有谁知道我哪里出了问题,这开始让我恼火了 我使用的是moodle 2.2和quick forms,它在提交时保存到数据库中,但返回表单时出错 mysqli::real_escape_string()希望参数1是字符串,数组在/$root/lib/dml/mysqli_native_moodle_database.php中给出 我还尝试将表单中的文档上传到课程上下文中,以便进行大规模的修改 <?php require_once("../../config.php"); $cou

请帮帮我,有谁知道我哪里出了问题,这开始让我恼火了

我使用的是moodle 2.2和quick forms,它在提交时保存到数据库中,但返回表单时出错

mysqli::real_escape_string()希望参数1是字符串,数组在/$root/lib/dml/mysqli_native_moodle_database.php中给出

我还尝试将表单中的文档上传到课程上下文中,以便进行大规模的修改

<?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();
?>

我刚刚加入这个网站,正在浏览有关moodle的帖子,我发现了这个帖子。我想你现在可能已经找到了这个问题的解决方案,但是,对于其他人来说:

当您在任何页面上显示moodle表单时,应执行以下操作:

if($form->is_cancelled()) {
    //Write the code to handle the event where user clicks the cancel 
    //button on the form
    //This is where (generally) you would use the redirect function
} else if($data = $form->get_data(true)) {
    //This is where you can process the $data you get from the form
} else {
    //This is where you should add the commands that display the page when 
    //displaying the form for first time (when page loads)
    echo $OUTPUT->header();
    echo $OUTPUT->heading();
    //Add other commands
    echo $OUTPUT->footer();
}
干杯
Sandeep

您的错误没有行号或堆栈跟踪。尝试安装xdebug,然后发布它将提供给您的更具体的错误消息。如上所述,您应该提供确切的错误消息。我注意到,插入后没有重定向:错误一定是由于与mform关联的数据引起的,因此,如果您仍然希望显示该页面,而不是返回正在编辑的内容的索引,则可以尝试重定向到同一页面。
if($form->is_cancelled()) {
    //Write the code to handle the event where user clicks the cancel 
    //button on the form
    //This is where (generally) you would use the redirect function
} else if($data = $form->get_data(true)) {
    //This is where you can process the $data you get from the form
} else {
    //This is where you should add the commands that display the page when 
    //displaying the form for first time (when page loads)
    echo $OUTPUT->header();
    echo $OUTPUT->heading();
    //Add other commands
    echo $OUTPUT->footer();
}