大家好,我的代码需要帮助,我不知道该怎么做。我有一个表格,学生选择考试机构,如果选择的考试机构是 zimsec 分数应该是空的,如果考试机构是剑桥分数不应该是空的,应该根据成绩取一个范围。validMarks 是我用来验证标记的函数,当我允许标记为空以适应 Zimsec 时,它停止工作。
我的 add.ctp
echo "<td>";
echo $this->Form->label('Mark(%): ');
echo "</td><td>";
echo $this->Form->input("ApplicantOlevelQualification.mark.$s",array('label'=>''));
echo "</td></tr>";
echo $this->Form->label('Exam Body<font color=red>*</font>');
$exambody=array(
'ZIMSEC'=>'ZIMSEC',
'CAMBRIDGE'=>'CAMBRIDGE'
);
echo $this->Form->select('exam_body_code',$exambody,array('empty'=>'Please Select','selected'=>false,'label'=>'Exam Body<font color="red">*</font>'));
我的控制器
$exam_body_code = $this->data['ApplicantOlevelQualification']['exam_body_code'];
'mark' => $this->data['ApplicantOlevelQualification']['mark'][$i],
我的模型
'exam_body_code' => array(
'notempty' => array(
'rule' => array('notempty'),
),
),
'mark' => array(
//'numeric' => array(
//'rule' => array('numeric'),
'rule' => array('validMarks'),
'message' => 'Wrong mark for this grade, please try again.',
'allowEmpty' => true,
// ),
),
public function validMarks($check) {
$grade=($this->data['ApplicantOlevelQualification']['grade']);
$mark=($this->data['ApplicantOlevelQualification']['mark']);
//var_dump($mark);
if($grade== 'A' && $mark>74) {
// $this->validationError( 'grade', 'Grade A must be greater than or equal to 75%' );
//Access $this->data and $check to compare your marks and grade;
return true;
} elseif( ($grade)== 'B' && ($mark>64)) {
return true;
} elseif( ($grade)== 'C' && ($mark)>50) {
return true;
} elseif( ($grade)== 'D' && ($mark)>40) {
return true;
} elseif( ($grade)== 'E' && ($mark)>30) {
return true;
} elseif( ($grade)== 'U' && ($mark)>0) {
return true;
} else {
return false;
}
//Access $this->data and $check to compare your marks and grade..
}