0
我是Yii框架的新手。目前,我有一個需要我使用Yii框架的項目。我想問一下,是否可以驗證數據庫中沒有保存的屬性?Yii Framework:在查看頁面驗證複選框
case: 我有一個複選框,需要用戶在它上面打勾才能移動到下一頁。如果用戶不勾選它,則會提示錯誤。如何以Yii格式驗證它?
有人可以教我如何改變下面的驗證,以適應Yii格式?驗證位置在哪裏?
在model.php內容
public $pdpa_agree;
public function rules()
{
array('pdpa_agree', 'required');
}
內容view.php
<?php
$form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'pdpaPolicy-form',
'enableAjaxValidation'=>true,
'type'=>'horizontal',
'htmlOptions' => array(
'enctype' => 'multipart/form-data',
"autocomplete"=>"off", //turn off auto complete in FF
)
));
?>
<?php echo $data->pdpa_content; ?>
<p class="cb_pdpa" style="font-weight:bold"><?php echo $form->checkbox($data,'pdpa_agree'); ?> I have read and understood the above policies and hereby give consent for CTES to use my <pd>*personal data</pd> in accordance to the policies listed out above.</p>
<div class="form-actions">
<?php
/*$this->widget('bootstrap.widgets.TbButton', array(
'buttonType' => 'submit',
'type' => 'primary',
'label'=>$model->isNewRecord ? 'PolicyAgreement' : 'Continue Registration',
));*/
?>
<input type="button" name="submit" value="Continue Registration" onclick="validateAgreement()">
</div>
<?php $this->endWidget(); ?>
<script>
function validateAgreement()
{
if($("#pdpa_agree").is(':checked'))
{
window.location.href = 'register?sourceID=CTES';
return true;
}
else
{
alert("Please tick on the agreement checkbox in order to proceed the registration!");
return false;
}
}
</script>
如何打開下面的驗證,以適應Yii的格式?
<script>
function validateAgreement()
{
if($("#pdpa_agree").is(':checked'))
{
window.location.href = 'register?sourceID=CTES';
return true;
}
else
{
alert("Please tick on the agreement checkbox in order to proceed the registration!");
return false;
}
}
</script>
謝謝。那麼我想知道,我該如何做驗證? – Verlee
你需要什麼驗證? –
嗨,我已編輯上述問題。我想知道如何更改上面的驗證以適應Yii格式?我應該在哪裏進行驗證? – Verlee