Yii Framework Forum: How to separate forms into 3 steps? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How to separate forms into 3 steps? Rate Topic: -----

#1 User is offline   Joe Storm 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 17-April 10

Posted 05 September 2010 - 11:32 AM

Using the blog sample ContactForm, I need to create a User Registration form where the fields are broken into a few pages, like Next Next Next Done...

Do I create in the model RegisterForm, RegisterForm_1, RegisterForm_2, RegisterForm_3 and the views/actions register, registerStep_2, registerStep_3, and so on?

Please help me with some examples on how to do this.

Thank you..

public function actionRegister()
{
  $model=new RegisterForm;
  if(isset($_POST['RegisterForm']))
  {
    $model->attributes=$_POST['RegisterForm'];
    if($model->validate())
    {
      $headers="From: {$model->email}\r\nReply-To: {$model->email}";
      mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers);
      Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
      $this->refresh();
    }
  }
  $this->render('registerStep_2',array('model'=>$model)); //<--- like this?
}

0

#2 User is offline   MiksIr 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 17
  • Joined: 01-September 10
  • Location:Russia, Moscow

Posted 05 September 2010 - 12:26 PM

In my case i'm using AR model directly.
    $user = $this->app->user;
    $step = $this->request->getParam('step');

    $model = UserForm::model()->findByAttributes(array('id'=>$user->id));
    if ($model === null)
    {
      $model = new UserForm();
      $model->id = $user->id;
    }

    $step = $step ? $step : 1;
    $model->setScenario('step'.$step);

    if ($this->request->getIsPostRequest())
    {
      $model->attributes = $this->request->getParam('UserForm');

      if ($model->validate() && $model->save())
      {
         $this->redirect(array('profile/first', 'step'=>$step+1));
      }
    }

    // parts of form included inside 'first' with renderPartial
    $this->render('first', array('model'=>$model, 'step'=>$step));
  }

And model validation for each step with 'on' => 'step1', 'on' => 'step2' etc
0

#3 User is offline   Ben 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 270
  • Joined: 15-March 09

Posted 05 September 2010 - 02:39 PM

Don't know if this is an option for you, but you could use one single html form to collect the data from users and use jquery/CSS to hide parts of it. So the click on "next" would only toggle what parts of the form are currently visible to the user. This way, you can implement a wizard without having to split forms and/or models.

As an example, try this one (don't know it, only did a quick search on google to show what I mean).
Don't like ads in my sig...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users