Users And Companies Registration In One Step

I am new to yii and tried to arrange a check on its website in several ways. At the moment I stopped at that created actionRegistration in siteController

        public function actionRegistration()


		$user = new User;

                $company = new Company;







                        if($user->validate()&& $company->validate())


                                $user->password = SHA1($user->password);

                                $user->signup_date = new CDbExpression("NOW()");


                                if ($user->save()) {


                                        $company->create_date = new CDbExpression("NOW()");


                                if ($company->save()) {

                                        $user->company_id = $company->id;

                                        $user->role = 'owneer';                                                        







                if (Yii::app()->user->isGuest){







<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(






); ?>

	<?php echo $form->errorSummary(array($user,$company)); ?>

	<div class="row">

            <?php echo $form->textField($user,'name',array('size'=>60,'maxlength'=>255, "id"=>"username")); ?>

            <?php echo $form->error($user,'name'); ?>


	<div class="row">

		<?php echo $form->textField($user,'email',array('size'=>60,'maxlength'=>255, "id"=>"email")); ?>

		<?php echo $form->error ($user,'email'); ?>


	<div class="row">		

		<?php echo $form->passwordField($user,'password',array('size'=>60,'maxlength'=>255)); ?>

		<?php echo $form->error($user,'password'); ?>



	<div class="row">

            <?php echo $form->textField($company,'name'); ?>

            <?php echo $form->error($company,'name'); ?>


 </div>      <!-- clearfix -->

 <div class="clear"></div>

 <!-- /clearfix -->

 <!-- <input class="submit" type="submit" name="submit_third" id="submit_third" value="" />-->

 <?php echo CHtml::submitButton('SUBMIT', array('class'=>"submit", 'type'=>'продолжить', 'name'=>"submit_third", 'id'=>"submit_third", 'value'=>"")); ?>

<?php $this->endWidget(); ?>


After sending a blank form, validation does not work… and I just see a blank form… What I did wrong?

Hi, welcome to Yii!

What did you mean the validation does not work ?

Did you set required attributes in your models ?

Blank form after of submitted blank form is a normal issue

If the user has not filled in any field, I should see the error message, but my form does not store data and shows no errors if the data were not provided…

The problem is the $_POST[‘registration-form’]

‘id’=>‘registration-form’, in your form does not mean submit will post ‘registration-form’ name




                {  ...   


  if(isset($_POST['User']) && isset($_POST['Company']))

                {  ... 

Yeah! It work!!! Thank you!!!