控制器如下
LoginForm如下
视图如下
<div class="loginbody">
<span class="systemlogo"></span>
<div class="loginbox">
<ul>
<?php $form = $this->beginWidget(‘CActiveForm‘,array(‘method‘=>‘post‘))?>
<li class="loginuser"><?php echo $form->textField($loginForm,‘username‘,array(‘class‘=>‘loginuserinput‘,‘value‘=>‘user‘,‘onclick‘=>‘JavaScript:this.value=""‘,"size"=>"20"));?></li>
<li class="loginpwd"><?php echo $form->passwordField($loginForm,‘password‘,array(‘class‘=>‘loginuserinput‘,‘value‘=>‘‘,‘onclick‘=>‘JavaScript:this.value=""‘,"size"=>"20"));?></li>
<li class="code"><?php echo $form->textField($loginForm,‘captcha‘,array(‘class‘=>‘loginuserinput‘,‘value‘=>‘‘,‘onclick‘=>‘JavaScript:this.value=""‘,"size"=>"8"));?>
<div style="float:right;margin-right:64px;"><?php $this->widget(‘CCaptcha‘,array(‘showRefreshButton‘=>false,‘clickableImage‘=>true,‘imageOptions‘=>array(‘alt‘=>‘点击换图‘,‘title‘=>‘点击换图‘,‘style‘=>‘cursor:pointer‘))); ?></div></li>
<div class="clb"></div>
<li><input name="login" type="submit" class="loginbtn" value="登录" /> <label><a href="#">忘记密码?</a></label></li>
<?php $this->endWidget();?>
</ul>
</div>
</div>
</body>
</html>
<script type="text/javascript">
$(function(){
<?php if($form->error($loginForm,‘password‘)){echo "alert(‘".str_replace(‘<div class="errorMessage">‘,‘‘,str_replace(‘</div>‘,‘‘,$form->error($loginForm,‘password‘)))."‘);";}?>
<?php if($form->error($loginForm,‘username‘)){echo "alert(‘".str_replace(‘<div class="errorMessage">‘,‘‘,str_replace(‘</div>‘,‘‘,$form->error($loginForm,‘username‘)))."‘);";}?>
<?php if($form->error($loginForm,‘captcha‘)){echo "alert(‘".str_replace(‘<div class="errorMessage">‘,‘‘,str_replace(‘</div>‘,‘‘,$form->error($loginForm,‘captcha‘)))."‘);";}?>
});
</script>