CCaptcha

hi, i have a very small problem, its more a question then a problem.

does ccaptcha only work with CFormModel or can i use it wirh CActiveRecord as well?

You can use it for both.

if that is so… i'm actually having a problem… what am i doing wrong?

it won't view the image, in contact it's visibly. gd2 works.

does somebody have an idea?

Please give more details, including your actions() method, relevant view code and model code.

ok sorry…

here are the facts:

controller:



class KundenController extends CController


{


	/**


	 * Declares class-based actions.


	 */


	public function actions()


	{


		return array(


			// captcha action renders the CAPTCHA image


			// this is used by the contact page


			'captcha'=>array(


				'class'=>'CCaptchaAction',


				'backColor'=>0xEBF4FB,


			),


		);


	}


...


	public function actionReg()


	{


		$kunden=new Kunden;





		if(isset($_POST['Kunden']))


		{


			$kunden->attributes=$_POST['Kunden'];


			$kunden->pwd=md5($_POST['Kunden']['pwd']);


			$subject = "Kundenanmeldung";


			$body = "Ein neuer Kunde hat sich registriert.n";


			$body .= "E-Mail: ".$kunde->email."n";


			


			if($kunden->validate() && $regform->validate())


				if($kunden->save())


					$headers="From: {$kunden->email}rnReply-To: {$kunden->email}";


					mail(Yii::app()->params['adminEmail'],$subject,$body,$headers);


					Yii::app()->user->setFlash('reg','Danke das Sie sich angemeldet haben, wir werden uns in Kürze mit ihnen in Verbindung setzen');


					$this->refresh();


		}


		$this->render('reg',array('kunden'=>$kunden));


	}

Model



class Kunden extends CActiveRecord


{


	public $verifyCode;


...


	public function rules()


	{


		return array(


			array(


'verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),


		);


	}


...


view

<?php $this->pageTitle=Yii::app()->name . ' - Registrierung'; ?>





<h2>New Kunden</h2>





<div class="actionBar">


[<?php echo CHtml::link('Kunden List',array('list')); ?>]


[<?php echo CHtml::link('Manage Kunden',array('admin')); ?>]


</div>





<?php if(Yii::app()->user->hasFlash('reg')): ?>


<div class="confirmation">


<?php echo Yii::app()->user->getFlash('reg'); ?>


</div>


<?php else: ?>





<div class="yiiForm">





<p>


Felder mit <span class="required">*</span> sind Pflichtfelder.


</p>





<?php echo CHtml::form(); ?>





<?php echo CHtml::errorSummary($kunden); ?>





<div class="simple">


<?php echo CHtml::activeLabel($kunden,'user'); ?>


<?php echo CHtml::activeTextField($kunden,'user',array('size'=>60,'maxlength'=>255)); ?>


</div>


<div class="simple">


<?php echo CHtml::activeLabelEx($kunden,'pwd'); ?>


<?php echo CHtml::activePasswordField($kunden,'pwd',array('size'=>60,'maxlength'=>255)); ?>


</div>


<div class="simple">


<?php echo CHtml::activeLabelEx($kunden,'pwd_repeat'); ?>


<?php echo CHtml::activePasswordField($kunden,'pwd_repeat',array('size'=>60,'maxlength'=>255)); ?>


</div>


<div class="simple">


<?php echo CHtml::activeLabelEx($kunden,'question'); ?>


<?php echo CHtml::activeDropDownList($kunden,'question',array('Frage1'=>'Frage 1', 'Frage2'=>'Frage 2')); ?>


</div>


<div class="simple">


<?php echo CHtml::activeLabelEx($kunden,'answer'); ?>


<?php echo CHtml::activeTextField($kunden,'answer',array('size'=>60,'maxlength'=>255)); ?>


</div>


<div class="simple">


<?php echo CHtml::activeLabelEx($kunden,'email'); ?>


<?php echo CHtml::activeTextField($kunden,'email',array('size'=>60,'maxlength'=>255)); ?>


</div>


<div class="simple">


<?php echo CHtml::activeLabelEx($kunden,'homepage'); ?>


<?php echo CHtml::activeTextField($kunden,'homepage',array('size'=>60,'maxlength'=>255)); ?>


</div>


<div class="simple">


<?php echo CHtml::activeLabelEx($kunden,'tel'); ?>


<?php echo CHtml::activeTextField($kunden,'tel',array('size'=>60,'maxlength'=>255)); ?>


</div>


<div class="simple">


<?php echo CHtml::activeLabelEx($kunden,'firma'); ?>


<?php echo CHtml::activeTextField($kunden,'firma',array('size'=>60,'maxlength'=>255)); ?>


</div>


<div class="simple">


<?php echo CHtml::activeLabelEx($kunden,'str'); ?>


<?php echo CHtml::activeTextField($kunden,'str',array('size'=>60,'maxlength'=>255)); ?>


</div>


<div class="simple">


<?php echo CHtml::activeLabelEx($kunden,'num'); ?>


<?php echo CHtml::activeTextField($kunden,'num',array('size'=>60,'maxlength'=>255)); ?>


</div>


<div class="simple">


<?php echo CHtml::activeLabelEx($kunden,'ort'); ?>


<?php echo CHtml::activeTextField($kunden,'ort',array('size'=>60,'maxlength'=>255)); ?>


</div>


<div class="simple">


<?php echo CHtml::activeLabelEx($kunden,'plz'); ?>


<?php echo CHtml::activeTextField($kunden,'plz',array('size'=>60,'maxlength'=>255)); ?>


</div>





<?php if(extension_loaded('gd')): ?>


<div class="simple">


	<?php echo CHtml::activeLabel($kunden,'verifyCode'); ?>


	<div>


	<?php $this->widget('CCaptcha'); ?>


	<?php echo CHtml::activeTextField($kunden,'verifyCode'); ?>


	</div>


	<p class="hint">Please enter the letters as they are shown in the image above.


	<br/>Letters are not case-sensitive.</p>


</div>


<?php endif; ?>





<div class="action">


<?php echo CHtml::submitButton('Anmelden'); ?>


</div>





</form>


</div><!-- yiiForm -->


<?php endif; ?>

i hope that is enough…

i kinda compared it to the contact code and i thought its quite equal.

apparently not…

Did you forget to declare 'verifyCode' in safeAttributes()? By default, safeAttributes() only include those table columns.

thanks for the reply… it was sth else though. it was denied by the accessRules()…