Password repeat and Ccaptcha issue

[Edit] - Topic locked - check last post for solution.

For the sake of those who end up trying to search for this problem I’ve made a new topic - makes it easier to find results, instead of just continuing an off topic titled problem in my other thread :).

I'm going to assume something is up with my rules defined in my user model. Because I basically copy and pasted the ccaptcha code from the contact form demo and used that. So here's what I have for my rules now, the only other issue I can think of is that because in my user db table, there is not a field for password 2 or captcha I'm thinking that may be an issue - so I defined public variables in the user model so they are saved when accessed through the form.

So here's a look at what I've done:



<?php


/**


	 * The followings are the available columns in table 'User':


	 * @var integer $id


	 * @var string $username


	 * @var string $password


	 * @var string $email


	 * @var string $question


	 * @var string $answer


	 */


	


	/*


	 * define repeat password variable & verify code variable


	 */


	public $password2;


	public $verifyCode;


?>


So that's a look at the defined variables of my user model class that extends AR

And here's my rules set. Within the site controller that's handling the register action there is no changes that say from the login action, yii checks for $_POST to be set, if so assigns the attributes their values and then validates them. So that's why I think the rules are the problem.



<?php


return array(


			array('username','length','max'=>32),


			array('password','length','max'=>64),


			array('password2','length','max'=>64),


			// compare password to repeated password


			array('password', 'compare', 'compareAttribute'=>'password2'),


			array('email','length','max'=>256),


			// make sure email is a valid email


			array('email','email'),


			// make sure username and email are unique


			array('username, email', 'unique'), 


			array('question','length','max'=>256),


			array('answer','length','max'=>128),


			array('username, password, password2, email, question, answer, verifyCode', 'required'),


			// verifyCode needs to be entered correctly


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


		);


?>


Now for the sake of covering all angles

Here are the consistent errors I get even when I know the passwords are the same and the captcha is correct.

Please fix the following input errors:

    * Password must be repeated exactly.

    * Repeat Password cannot be blank.

    * Verification Code cannot be blank.

    * The verification code is incorrect.

And for the sake of showing how I'm presenting them



<div class="simple">


<?php echo CHtml::activeLabel($form,'password', array('style'=>'width:150px;')); ?>


<?php echo CHtml::activePasswordField($form,'password') ?>


</div>





<div class="simple">


<?php echo CHtml::activeLabel($form,'password2', array('style'=>'width:150px;')); ?>


<?php echo CHtml::activePasswordField($form,'password2') ?>


</div>





...





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


<div class="simple">


	<?php echo CHtml::activeLabel($form,'verifyCode', array('style'=>'width:150px;')); ?>


	<div>


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


	<?php echo CHtml::activeTextField($form,'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; ?>


Any suggestions would be great :)

Ok reading http://www.yiiframew…ring-validation

I tried those suggestions, making _repeat instead of 2 and no dice. Now I used the 'password', 'compare', 'on'=>'register' and that did make it so the first password would pass fine but the repeated one would say it can't be blank. This implies that it's not recognizing the page as the register page or else it would try to compare both passwords (but it's not).

So tried a few things but nothing is working, and no ideas on the Captcha yet.

Ok here's the fix: I was reading up on other areas and read about safeAttributes. Now by default AR already defines safe user inputs (in which case most of the time you modify so that a model id isn't tampered with) in my case because the password2 and verifyCode were not part of the user table they weren't defined by default by the user AR model and thus they weren't considered safe attributes.

Here's my fix:



<?php


public function safeAttributes()


	{


		return array(


			'username, password, password2, email, question, answer, verifyCode',


		);


	}


?>