Note that there are some explanatory texts on larger screens.

plurals
  1. POyii captcha not validating properly
    primarykey
    data
    text
    <p>Im trying to add a captcha using yii to my contact form, but there is some problem with validation.</p> <p>My model</p> <pre><code>class ContactForm extends CFormModel { public $verifyCode; public function rules() { return array( array('verifyCode', 'captcha', 'allowEmpty'=&gt;!CCaptcha::checkRequirements(),'on'=&gt;'captchaRequired'), array('verifyCode', 'safe'), ); } } </code></pre> <p>Code in my controller</p> <pre><code>public function filters() { return array( 'accessControl', ); } public function accessRules() { return array( array( 'allow', //allow all users to perform advertise and index action 'actions' =&gt; array('advertise','index', 'captcha'), 'users' =&gt; array('*'), ), ); } public function actions() { return array( // captcha action renders the CAPTCHA image displayed on the contact page 'captcha' =&gt; array( 'class' =&gt; 'CCaptchaAction', 'backColor' =&gt; 0xFFFFFF, 'testLimit'=&gt; '2', ), ) } public actionAdvertise() { $model = new ContactForm; $model-&gt;scenario = 'captchaRequired'; if($model-&gt;validate()){ //some code } else { $this-&gt;render('advertise', array('model' =&gt; $model)); } } } </code></pre> <p>Code in my advertise.php view</p> <pre><code> &lt;form action="" method="post"&gt; &lt;?php $form=$this-&gt;beginWidget('CActiveForm',array( 'id'=&gt;'contact-form', 'enableAjaxValidation'=&gt;false, )); ?&gt; &lt;?php if(CCaptcha::checkRequirements()){ ?&gt; &lt;div class="row"&gt; &lt;div class="contact_field_wrapper"&gt; &lt;?php echo '&lt;b&gt;ARE YOU HUMAN?&lt;/b&gt;&lt;br /&gt;'.$form-&gt;labelEx($model, 'verifyCode'); ?&gt; &lt;div class="captcha user-captcha"&gt; &lt;?php $this-&gt;widget('CCaptcha',array( 'captchaAction'=&gt;'site/captcha' )); ?&gt; &lt;?php echo $form-&gt;error($model, 'verifyCode'); ?&gt; &lt;?php echo '&lt;br /&gt;'.$form-&gt;textField($model,'verifyCode'); ?&gt; &lt;div class="hint"&gt;Please enter the letters as they are shown in the image above.&lt;br/&gt; Letters are not case-sensitive. &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;?php } ?&gt; &lt;?php $this-&gt;endWidget(); ?&gt; &lt;/form&gt; </code></pre> <p>The problem is that <code>$model-&gt;validate()</code> returns false when correct code in inputted. <code>$model-&gt;getErrors()</code> is always returning <strong>'Verification code is incorrect'.</strong></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload