我已经更改了很多代码。
这是我的控制器中的代码:
public function actionRequestTV() {
$this->layout = '//layouts/column1';
$this->bodyclass = 'bodygrey_without_leftbg';
$model = new Reqtv();
if (isset($_POST['Reqtv'])) {
if ($model->validate()) {
$model->attributes = $_POST['Reqtv'];
if ($model->save())
$this->redirect(array('step2', 'id' => $model->REQTVID));
}
}elseif (isset($_POST['BP'])) {
if ($model->validate()) {
$model->attributes = $_POST['BP'];
if (!$model->save()) {
print_r($model->getErrors());
}else
$this->redirect(array('step2B', 'id' => $model->REQTVID));
}
}else
$this->render('reqtvform_step1', array(
'model' => $model,
));
}
这是规则:
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('BPID, SK', 'numerical', 'integerOnly' => true),
array('BPMOBILE', 'numerical'),
array('TVID, TVPASS', 'length', 'max' => 50),
array('PROBLEM', 'length', 'max' => 250),
array('BPCP, BPMOBILE, BPEMAIL', 'length', 'max' => 255),
array('SK', 'ceksk'),
array('BPEMAIL', 'email'),
array('PSNO', 'cekPSNO'),
// array('SK, PROBLEM, TVID, TVPASS', 'required', 'on' => 'step2'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('REQTVID, BPID, TVID, TVPASS, PROBLEM, SK, BPCP, BPMOBILE, BPEMAIL, PSNO', 'safe', 'on' => 'search'),
);
}
在将我的代码从此代码更改为更简单的代码后,它已经能够保存这些值。但是,有些规则不起作用,例如 ceksk 规则。这是ceksk的代码:
public function ceksk() {
if($this->SK){
if (!$this->SK == 1) {
$this->addError('SK', 'Maaf, anda harus mencentang persetujuan syarat & ketentuan sebelum melanjutkan');
return false;
}
}
}
更新
我的 ceksk 规则已经生效。但我决定改用 JQuery:
<?php
Yii::app()->clientScript->registerScript('JQuery', "
$('#kirim').click(function() {
if ($('#SK').attr('checked')) {
return true;
}else{
alert('Anda belum mencentang Syarat & Ketentuan');
return false;
}
});
");
?>
但我的其他规则仍然不起作用。我的 cekPSNO 规则实际上是有效的。但是当它发现错误时,它会将我带到一个空白的白色页面,而不是停留在表单页面并显示错误。这是代码:
public function cekPSNO() {
if ($this->PSNO) {
$psno = Ps::model()->findByAttributes(array('PSNO' => $this->PSNO));
//check cdsn ada atau tidak
if ($psno === null) {
$this->addError('PSNO', 'Nomor PS tidak ditemukan, silahkan periksa Nomor PS anda !');
return false;
} else {
if (date('Y-m-d') > $psno->TGLBERAKHIR) {
$this->addError('PSNO', 'Premium Support sudah expired !');
return false;
}
}
}
}
拜托,我们非常感谢您的帮助。谢谢你 :))