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(isset($_POST['registration-form']))

		{       

			$user->attributes=$_POST['User'];

                        $company->attributes=$_POST['Company'];

                        

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

                            {

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

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

                                        

                                if ($user->save()) {

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

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

                                        } 

                                if ($company->save()) {

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

                                        $user->role = 'owneer';                                                        

                                        $user->save();

                                } 

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

                            }

		}

                

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

                    $this->render('registration',array('user'=>$user,'company'=>$company));

                }else{

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

                }                        

        }

registration.php


<div class="form">


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

	'id'=>'registration-form',

	'enableAjaxValidation'=>false,

    'clientOptions'=>array(

		'validateOnSubmit'=>true,

	))

); ?>


	<?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>


	<div class="row">

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

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

	</div>


	<div class="row">		

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

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

	</div>

        

	<div class="row">

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

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

	</div>


 </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(); ?>

</div>

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

So,

Replace


  if(isset($_POST['registration-form']))

                {  ...   

with


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

                {  ... 

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