2013-01-25 41 views
0

我正在使用Moodle安装v 2.3.4,并在NEWMODULE插件中创建了一个简单的表单并使用它来输入2个字段名称和说明。当在moodle表单中按下'submit'按钮时将数据插入到数据库中

我想插入数据库中输入的数据,但数据没有被插入。 按下提交后,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'); 
} 
} 

回答

1

你的文件结构和代码按照活动的插件是不正确的看看

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

请按照文档中的说明进行操作。

因为您正在使用mooodleform_mod的clase,并且您不需要在您的文件夹中创建该文件,所以一旦您根据mod插件遵循正确的语法,它的核心文件将自动打开。

如果你只是想将数据存储到db中,那么使用本地插件比mod插件更容易。

谢谢。

相关问题