Registration In Several Steps.

Hi all! I’m a junior. It is necessary to implement registration of several steps.

To do this in siteController I created aсtionRegistration()


public function actionRegistration()

	{

		$userModel = new User;

		$companyModel = new Company;


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

		{

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

			$userModel->save();		

		}


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

		{

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

			$companyModel->save();		

		}		


		$this->render('registration');  

	}

and in the folder views/site/ I created file registration.php


<div id="container">

<form action="#" method="post">    

<div id="first_step">

<div class="form">


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

	'id'=>'user-form',

	'enableAjaxValidation'=>true,

)); ?>


	<?php echo $form->errorSummary($userModel); ?>


	<div class="row">

		<?php echo $form->labelEx($userModel,'name'); ?>

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

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

	</div>


	<div class="row">

		<?php echo $form->labelEx($userModel,'phone'); ?>

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

		<?php echo $form->error ($userModel,'phone'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($userModel,'mail'); ?>

		<?php echo $form->textField($userModel,'mail',array('size'=>60,'maxlength'=>255)); ?>

		<?php echo $form->error($userModel,'mail'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($userModel,'password'); ?>

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

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

	</div>

        

	<div class="row">

            <?php echo $form->labelEx($userModel,'confirmPassword'); ?>

            <?php echo $form->passwordField($userModel,'confirmPassword'); ?>

            <?php echo $form->error($userModel,'confirmPassword'); ?>

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton($userModel->isNewRecord ? 'Create' : 'Save'); ?>

	</div>


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

</div>

</div>

    

<div id="second_step">

<div class="form">


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

	'id'=>'company-form',

	'enableAjaxValidation'=>true,

)); ?>

    

		<?php echo $form->errorSummary($companyModel); ?>

	<div class="row">

		<?php echo $form->labelEx($companyModel,'name'); ?>

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

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

	</div>


	<div class="row">

		<?php echo $form->labelEx($companyModel,'country'); ?>

		<?php echo $form->textField($companyModel,'country',array('size'=>60,'maxlength'=>255)); ?>

		<?php echo $form->error($companyModel,'country'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($companyModel,'sity'); ?>

		<?php echo $form->textField($companyModel,'sity',array('size'=>60,'maxlength'=>255)); ?>

		<?php echo $form->error($companyModel,'sity'); ?>

	</div>


	<div class="row">

		<?php echo $form->labelEx($companyModel,'oween_year'); ?>

		<?php echo $form->textField($companyModel,'oween_year'); ?>

		<?php echo $form->error($companyModel,'oween_year'); ?>

	</div>


	<div class="row buttons">

		<?php echo CHtml::submitButton($companyModel->isNewRecord ? 'Create' : 'Save'); ?>

	</div>

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

</div>

</div><!-- form -->

</form>

</div>

when the page loads I get error

undefinde: userModel in <?php echo $form->errorSummary($userModel); ?>

help me mates!

You are doing a mistake here ->

when you call





  $this->render('registration'); 




you are not passing $userModel or $companyModel models which you created in the controller. Change it to -





 $this->render('registration',array(

      'userModel'=>$userModel,

      'companyModel'=>$companyModel,

    ));




[color="#FF0000"]Click +1 if you are happy with my answer[/color]

I change it…

But now i see error


Use of undefined constant id - assumed 'id'

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

how fix it?

or I should bring the form code in files, _userModel and _companyModel?





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




Show me your userModel ?

change

id=>"username"

to

"id"=>"username"

Hello, today i was looking for something similar, because my need is a little bit different, perhaps during research i found this extension, that i think will be usefull for you:

here’s the extension’s link: Wizard Behavior Extensions

here’s my problem topic: Skip validation on specific condition

I hope that will help you.

Regards

Francesco

I just built a 2 page submit and it was a bit tricky to understand at first. I got the example from one of the Packt books on yii and multi-page forms and it was a good starting example but not quite complete. Yii does most of the work, and has a lot of provisions for handleing field validation etc. The packt book was really more like a pamphlet with the amount of content, but it did have a good start.

Saving and passing state of the model on each render was important, and initially tricky to understandafter working through the example it’s not bad.

It gets tricky with dependent dropdowns and related ui, but if just simple forms it should not be that bad. I think I found a few pages on the web that had examples. Last one I found was the wizzard like component in the Yii extension (I can’t remember the name) I have not used it but looked good for multi-page forms.

Sandy

Thank you all for the answers!