cancel
最初我不使用moodle form
. 我的表格如下所示:
require_once("{$CFG->libdir}/formslib.php");
class quest_form extends moodleform {
function definition() {
global $DB;
$mform =&$this->_form;
$mform->addElement('header','displayinfo', 'Add Question');
// add question.
$mform->addElement('editor', 'title', 'Question');
$mform->addRule('title', null, 'required', null, 'client');
$mform->setType('title', PARAM_RAW);
// add answer.
$mform->addElement('editor', 'answer', 'Answer');
$mform->addRule('answer', null, 'required', null, 'client');
$mform->setType('answer', PARAM_RAW);
$mform->addElement('hidden', 'blockid');
$mform->setType('blockid', PARAM_RAW);
$mform->addElement('hidden', 'courseid');
$mform->setType('courseid', PARAM_RAW);
$this->add_action_buttons(false, 'submit');
}
现在我想cancel
在我的表单中使用按钮,所以我替换了该行
$this->add_action_buttons(false, 'submit');
和
$this->add_action_buttons(true, 'submit');
按钮显示成功,cancel
但在单击cancel
按钮时the form gets submitted
(即使表单字段中没有数据)。
我该如何解决这个问题?我还有什么想念的吗??
请帮我...
编辑
取决于罗素英格兰的回答。我尝试如下:
$qform = new quest_form ();
if ($qform ->is_cancelled()){
redirect("view.php?id={$cid}");
}else{
$qform = new pool_form("pool_action.php?id={$cid}&qpid={$questplace->id}&qtype={$qtype}");
}
$qform ->display();
但仍然cancel button
提交表单。