1

私はMoodleインストールv2.3.4を使用しており、NEWMODULEプラグインで簡単なフォームを作成し、それを使用して名前と説明の2つのフィールドを入力しています。

データベースに入力したデータを挿入したいのですが、データが挿入されません。送信を押した後、moodleはmodedit.phpを探しますが、これはもちろん現在のディレクトリにないため、「ページが見つかりません」というエラーが表示されます。

コードスニペットが表示されます:make_form.php(フォームページ):

<?php
require_once('../../config.php');
require_once('mod_form.php');
require_login($course, true);

echo $OUTPUT->header();
$mform = new mod_testform_mod_form();

if ($mform->is_cancelled()) {

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

//      print_object($fromform);    
    $record = new stdClass();       
    $record->id='';
    $record->name= $fromform->name;
    $record->description= $fromform->desc;
    $DB=insert_record('testform_details', $record, false);
    $mform->display();
}
else {
    $mform->set_data($toform);
    $mform->display();
    print_footer($course);
}
?>

mod_form.php

<?php

defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/course/moodleform_mod.php');

class mod_testform_mod_form extends moodleform_mod {

public function definition() {

    $mform = $this->_form;

    $mform->addElement('header', 'general', get_string('general', 'testform'));
    $mform->addElement('text', 'name', get_string('name', 'testform'));
    if (!empty($CFG->formatstringstriptags)) {
        $mform->setType('name', PARAM_TEXT);
    } else {
        $mform->setType('name', PARAM_CLEAN);
    }
    $mform->addRule('name', null, 'required', null, 'client');
    $mform->addHelpButton('name', 'name', 'testform');

//      $this->add_intro_editor();
    $mform->addElement('editor', 'desc', get_string('description','testform'));
    $mform->setType('desc', PARAM_RAW);
    $mform->addHelpButton('desc', 'description', 'testform');

    $buttonarray=array();
    $buttonarray[] = &$mform->createElement('submit', 'submitbutton', get_string('savechanges'));
    $buttonarray[] = &$mform->createElement('reset', 'resetbutton', get_string('reset'));
    $buttonarray[] = &$mform->createElement('cancel');
    $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
    $mform->closeHeaderBefore('buttonar');
}
}
4

1 に答える 1

1

アクティビティプラグインによると、ファイル構造とコードが正しくありません。

http://docs.moodle.org/dev/Activity_modules

ドキュメントに従って正確に従ってください。

mooodleform_modのクラスを使用しているため、modedit.phpのエラーが発生します。このファイルをフォルダーに作成する必要はありません。このファイルは、modプラグインに従って正しい構文に従うと、コアファイルが自動的に開きます。

データをdbに保存したいだけの場合は、modプラグインよりも簡単なローカルプラグインを使用してください。

ありがとう。

于 2013-01-26T08:56:48.450 に答える