0
我需要自定義驗證提交,我做了如下編碼: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 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;
}
}
當我點擊提交按鈕,它直接提交,但不檢查我已內提到的驗證我的
'函數驗證'。我該怎麼辦??