Php Moodle验证不起作用
我需要在提交时进行自定义验证,我的编码如下:Php Moodle验证不起作用,php,moodle,Php,Moodle,我需要在提交时进行自定义验证,我的编码如下: <?php require_once("{$CFG->libdir}/formslib.php"); class pool_status_form extends moodleform { function definition() { global $DB, $USER, $qnsCount; $mform =&$this->_form; //number of question per use
<?php
require_once("{$CFG->libdir}/formslib.php");
class pool_status_form extends moodleform {
function definition() {
global $DB, $USER, $qnsCount;
$mform =&$this->_form;
//number of question per user
$mform->addElement('text', 'peruser', get_string('peruserquestion', 'qpool'), array('id' => 'peerqn'));
$mform->addRule('peruser', null, 'required', null, 'client');
$mform->addRule('peruser', null, 'numeric', null, 'client');
$mform->setType('peruser', PARAM_RAW);
//$this->add_action_buttons(false, 'SAVE');
$mform->addElement('submit', 'subbtn', get_string("buttonlabel", "qpool"));
}
public function validation($data, $files) {
$errors = parent::validation($data, $files);
if (($data['peruser'])>3) {
$errors['peruser'] = "Error..";
}
return $errors;
}
}
“验证”功能在服务器上运行。只需调用$form->get_data(),它就会触发 另外,为什么要添加两次“必需”规则? 为什么数据类型是PARAM_RAW?我觉得它像PARAM_INT