如何在moodle中创建自定义表单? [英] How to create a custom form in moodle?

查看:44
本文介绍了如何在moodle中创建自定义表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在moodle中创建一个自定义表单并将表单数据存储在数据库表中.我一直在研究moodle表单库,但它对我来说太复杂了.

I want to create a custom form in moodle and store the form data in database table. I've been studying moodle form library but it's too complex for me.

任何有关如何在 Moodle 中创建自定义表单并将表单数据存储在数据库中的帮助或指导或教程或参考指南或电子书将不胜感激.

Any help or guidance or tutorial or reference guide or ebook on how to create custom forms in moodle and store the forms data in the database will be much appreciated.

推荐答案

您有多种方法可以做到.更清洁的是使用 Form API (http://docs.moodle.org/dev/Form_API).

You have several ways to do it. The cleaner is to use the Form API (http://docs.moodle.org/dev/Form_API).

顺便说一下,您可以使用页面 API (http://docs.moodle.org/dev/Page_API).

By the way, you can easily create your own form using PHP in a local plugin, using the Page API (http://docs.moodle.org/dev/Page_API).

这是一个简单的例子:

<?php

require_once('../../config.php');
global $CFG, $PAGE;

$PAGE->set_context(context_system::instance());
$PAGE->set_pagelayout('standard');
$PAGE->set_title('Form name');
$PAGE->set_heading('Form name');
$PAGE->set_url($CFG->wwwroot.'/local/yourform/index.php');
echo $OUTPUT->header();

?>

<form method="post" action="post.php">
    ... Your form code goes here
</form>

<?php

... Your PHP data handling code

echo $OUTPUT->footer();

?>

将此代码放入 Moodle 根目录下的本地"目录中的新目录中.示例:

Put this code into a new directory inside the "local" directory from Moodle root. Example :

/moodle/local/yourform/index.php

然后,通过在 Moodle 根 URL 的末尾添加 local/yourform/index.php 来访问您的表单.

Then, access your form by adding local/yourform/index.php at the end of your Moodle root URL.

这篇关于如何在moodle中创建自定义表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆