passwords and forms

I have a user creation form and the password field with the reapet password

Quote

<div class="simple">

<?php echo CHtml::activeLabelEx($model,'user_password'); ?>

<?php echo CHtml::activePasswordField($model,'user_password',array('size'=>60,'maxlength'=>150)); ?>

</div>

<div class="simple">

<?php echo CHtml::Label('Reapet password','user_password2'); ?>

<?php echo CHtml::PasswordField('user_password2','',array() ); ?>

</div>

At the poast of the form I have the error

Quote

Property "users.user_password2" is not defined.

I uses this validation

Quote

array('user_password', 'compare', 'compareAttribute'=>'user_password2','on' => 'insert'),

What is wrong?

user_password2 doesn't belong to the model. I think this is the problem…

include it in safe attributes

This is a form model, right?

Yes, the user_password is at db, the user_password2 not.

I do

 

Quote

public function safeAttributes()

    {

        return array(

            parent::safeAttributes(),

        'insert' => 'user_password2,user_nick,user_password,user_name,user_email',

        );

    }

//…

public function rules()

    {

        return array(

            array('user_nick', 'required'),

            array('user_password', 'required','on' => 'insert'),

            array('user_email', 'email'),

            array('user_password', 'compare', 'compareAttribute'=>'user_password2','on' => 'insert'),         

        );

    }

but now even I write something at username and password there is the error

Quote

Please fix the following input errors:

    * Username cannot be blank.

    * Password cannot be blank.

Here's my general register form…



<?php





class RegisterForm extends CFormModel


{


	public $m_sUserName;


	public $m_sPassword;


	public $m_sPasswordConfirm;


	public $m_sEmailAddress;


	public $m_sPasswordHint;


	public $m_sFirstName;


	public $m_sLastName;


	public $m_iCountryCode;


	public $m_iStateCode;


	public $m_sProvinceText;


	public $m_sPostalCode;





	/**


	* Validation rules


	*


	*/


	public function rules()


	{


		return array(


			array( 'm_sUserName, m_sPassword, m_sEmailAddress, m_sFirstName, m_sLastName, m_iCountryCode, m_sPostalCode, m_sPasswordHint', 'required' ),


			array( 'm_sPasswordConfirm', 'required', 'on' => 'register' ),


			array( 'm_sPassword', 'compare', 'on' => 'register' ),


			array( 'm_sUserName', 'register' ),


		);


	}





	/**


	* Friendly labels


	*


	*/


	public function attributeLabels()


	{


		return(


			array(


				'm_sPasswordConfirm' => 'Retype Your Password',


				'm_iCountryCode' => 'Your Country',


				'm_iStateCode' => 'State (US Only)',


				'm_sProvinceText' => 'Province (Non-US)',


				'm_sPostalCode' => 'Zip/Postal Code',


			)


		);


	}





	/**


	* Registers the user...


	*


	*/


	public function register()


	{


		if ( ! $this->hasErrors() )


		{


			$_dbc = new CDbCriteria;


			$_dbc->select = 'user_name_text';


			$_dbc->condition = 'user_name_text = :user_name_text';


			$_dbc->params = array( ':user_name_text' => $this->m_sUserName );





			$_oUser = User::model()->find( $_dbc );





			//	Check if username has already been registered


			if ( null == $_oUser )


			{


				$_oUser = new User();


				$_oUser->user_name_text = $this->m_sUserName;


				$_oUser->first_name_text = $this->m_sFirstName;


				$_oUser->last_name_text = $this->m_sLastName;


				$_oUser->country_code = $this->m_iCountryCode;


				$_oUser->state_code = $this->m_iStateCode;


				$_oUser->prov_text = $this->m_sProvinceText;


				$_oUser->password_text = md5( $this->m_sPassword );


				$_oUser->password_hint_text = $this->m_sPasswordHint;


				$_oUser->email_addr_text = $this->m_sEmailAddress;


				$_oUser->register_date = date( 'c' );


				$_oUser->last_logon_date = date( 'c' );


				$_oUser->visit_count_nbr = 0;


				$_oUser->lmod_date = date( 'c' );


				$_oUser->member_type_code = 10001;





				if ( $_oUser->save() )


				{


					$_oIdent = new UserIdentity( $this->m_sUserName, $this->m_sPassword );


					$_oIdent->authenticate();


					$_iDuration = 3600 * 24 * 30;





					Yii::app()->user->login( $_oIdent, $_iDuration );


				}


				else


				{


					$this->addError( 'm_sUserName', 'Unable to save new user' );


				}


			}


			else


			{


				$this->addError( 'm_sUserName', 'The user name you have chosen is already in use' );


			}


		}


	}


}


and my view



		<fieldset>


			<legend>Login Name and Password</legend>


			<div class="simple">


				<?php echo CHtml::activeLabel( $_oForm, 'm_sUserName' ); ?>


				<?php echo CHtml::activeTextField( $_oForm, 'm_sUserName' ) ?>


			</div>





			<div class="simple">


				<?php echo CHtml::activeLabel( $_oForm, 'm_sPassword' ); ?>


				<?php echo CHtml::activePasswordField( $_oForm, 'm_sPassword' ) ?>


			</div>





			<div class="simple">


				<?php echo CHtml::activeLabel( $_oForm, 'm_sPasswordConfirm' ); ?>


				<?php echo CHtml::activePasswordField( $_oForm, 'm_sPasswordConfirm' ) ?>


			</div>





			<div class="simple">


				<?php echo CHtml::activeLabel( $_oForm, 'm_sPasswordHint' ); ?>


				<?php echo CHtml::activeTextField( $_oForm, 'm_sPasswordHint' ) ?>


			</div>


		</fieldset>








I manage to create the model,view and controller or the "new user" creation but I want this form to be edited only by users that are "log on".

How can I do that? the code

class RegisterForm extends CFormModel {  


   public $m_sUserName;


   public $m_sPassword;


   public $m_sPassword_repeat;


   public $m_sEmailAddress;


 public $m_sFirstName;   


   public function rules()


   {


      return array(


         array( 'm_sUserName, m_sPassword, m_sEmailAddress, m_sFirstName,m_sPassword_repeat', 'required' ),


         array( ' m_sEmailAddress', 'email' ),        


         array( 'm_sPassword', 'compare' ),


         array( 'm_sUserName', 'register' ),


      );


   }  


   public function attributeLabels()


   {


      return(


         array(


              


                 'm_sPassword' => 'Password',


               'm_sPassword_repeat' => 'Retype Your Password',          


          


         )


      );


   }  


   public function register()


   {


      if ( ! $this->hasErrors() )


      {


         $_dbc = new CDbCriteria;


         $_dbc->select = 'user_nick';


         $_dbc->condition = 'user_nick = :user_name_text';


         $_dbc->params = array( ':user_name_text' => $this->m_sUserName );





         $_oUser = Users::model()->find( $_dbc );       


         if ( null == $_oUser )


         {


            $_oUser = new Users();


            $_oUser->user_nick= $this->m_sUserName;


             $_oUser->user_password = md5( $this->m_sPassword );


           $_oUser->user_name = $this->m_sFirstName;


            $_oUser->user_email = $this->m_sEmailAddress;          





            if ( $_oUser->save() )            {             


            }


            else


            {


               $this->addError( 'm_sUserName', 'Unable to save new user' );


            }


         }


         else


         {


            $this->addError( 'm_sUserName', 'The user name you have chosen is already in use' );


         }


      }


   }


}
class UpdateController extends CController {


    //put your code here


    public function accessRules()


	{


		return array(


			array('allow',


				'actions'=>array('create'),


				'users'=>array('@'),


			),





			array('deny',  // deny all users


				'users'=>array('*'),


			),


		);


	}


    


  public function actionCreate()


{


    $_oForm=new RegisterForm();


  


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


    {$_oForm->attributes=$_POST['RegisterForm'];


        // collects user input data


     //   $form->attributes=$_POST['LoginForm'];


        // validates user input and redirect to previous page if validated


        if($_oForm->validate())


            $this->redirect(Yii::app()->user->returnUrl);


    }





    $this->render('create',array('_oForm'=>$_oForm));


}





}

I found id, I had to write this

public function filters()


    {


        return array(


            'accessControl',


        );


    }

Yup, that'll do it.