本文整理汇总了PHP中question_type::validate_form方法的典型用法代码示例。如果您正苦于以下问题:PHP question_type::validate_form方法的具体用法?PHP question_type::validate_form怎么用?PHP question_type::validate_form使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类question_type
的用法示例。
在下文中一共展示了question_type::validate_form方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate_form
public function validate_form($form) {
switch($form->wizardpage) {
case 'question':
$calculatedmessages = array();
if (empty($form->name)) {
$calculatedmessages[] = get_string('missingname', 'qtype_calculated');
}
if (empty($form->questiontext)) {
$calculatedmessages[] = get_string('missingquestiontext', 'qtype_calculated');
}
// Verify formulas
foreach ($form->answers as $key => $answer) {
if ('' === trim($answer)) {
$calculatedmessages[] = get_string(
'missingformula', 'qtype_calculated');
}
if ($formulaerrors = qtype_calculated_find_formula_errors($answer)) {
$calculatedmessages[] = $formulaerrors;
}
if (! isset($form->tolerance[$key])) {
$form->tolerance[$key] = 0.0;
}
if (! is_numeric($form->tolerance[$key])) {
$calculatedmessages[] = get_string(
'tolerancemustbenumeric', 'qtype_calculated');
}
}
if (!empty($calculatedmessages)) {
$errorstring = "The following errors were found:<br />";
foreach ($calculatedmessages as $msg) {
$errorstring .= $msg . '<br />';
}
print_error($errorstring);
}
break;
default:
return parent::validate_form($form);
break;
}
return true;
}