大家好,我的代码需要帮助。我有一个表格,学生可以选择他们获得的科目、分数和成绩。科目和成绩是一个下拉菜单,它们处于循环中。我希望学生至少输入五门科目,包括英语。每个主题都由一个主题代码引用。保存一组学生详细信息。你能帮我做这件事吗?
我的控制器功能如下
public function add($app_id = null) {
if($app_id != null){
if ($this->request->is('post')) {
//saving the data in variables
$applicant_id = $this->data ['ApplicantOlevelQualification']['applicants_detail_id'];
$centre_number = $this->data['ApplicantOlevelQualification']['centre_number'];
$candidate_number = $this->data['ApplicantOlevelQualification']['candidate_number'];
$exam_body_code = $this->data['ApplicantOlevelQualification']['exam_body_code'];
$year_written = $this->data['ApplicantOlevelQualification']['year_written'];
$sittings=$this->request->data['ApplicantOlevelQualification']['number_of_sittings'];
// debug($sittings);die();
for ($i = 1; $i < sizeof($this->data['ApplicantOlevelQualification']['olevel_subject_code']); $i++) {
if ($this->data['ApplicantOlevelQualification']['olevel_subject_code'][$i] != "") {
$this->ApplicantOlevelQualification->create();
$this->ApplicantOlevelQualification->id = null;
$this->ApplicantOlevelQualification->set(array(
'applicants_detail_id' => $app_id,
'olevel_subject_code' => $this->data['ApplicantOlevelQualification']['olevel_subject_code'][$i],
'grade' => $this->data['ApplicantOlevelQualification']['grade'][$i],
'centre_number'=> $centre_number,
'candidate_number'=> $candidate_number,
'exam_body_code'=> $exam_body_code,
'year_written'=> $year_written,
)
);
//$appeng = $this->ApplicantOlevelQualification->find('list',array('fields'=> array('olevel_subject_code','grade'), 'conditions'=>array('ApplicantOlevelQualification.olevel_subject_code'=>'8900',)));
//debug(($this->data->ApplicantOlevelQualification);die();
/* if($appeng !="8900"){
$this->Session->setFlash(__('English is a prerequisite for application to procceed'));
$this->redirect(array('action' => 'add',$app_id));
} */
if ($this->ApplicantOlevelQualification->save()) {
$this->Session->setFlash(__('Your O\'level Qualifications have been saved'));
} else {
$this->Session->setFlash(__('Your O\'level Qualifications failed to save.'));
}
}
}
我的模型如下
public $validate = array(
'grade' => array(
'notempty ddd' => array(
'rule' => array('notempty'),
//'rule' => '/^[A-Z]{1}$/i',
'message' => 'Enter a valid grade, in capital letters!',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
'olevel_subject_code' => array(
'numeric' => array(
'rule' => array('numeric'),
//'message' => 'Your custom message here',
//'allowEmpty' => false,
//'required' => false,
//'last' => false, // Stop validation after this rule
//'on' => 'create', // Limit validation to 'create' or 'update' operations
),
),
);
目前,此代码捕获科目和成绩以及详细信息,而不检查学生是否输入了所需的最少 5 门科目及其成绩。如果可以,请你帮助我。谢谢你。