-1

i want create register page in 3 step:

Step1: Basic Infomation (ext: example.site/register/step1)

Step2: Profile Infomation (ext: example.site/register/step2)

Step3: Done (ext: example.site/register/step3)

looke like: enter image description here

Somebody can help me?

John Aston
  • 127
  • 3

1 Answers1

0

To Achieve something like this you have two options:

  1. Do it without reloading the page using javascript to show and hide relevant fields. As you declare a different url for each of your gui-prototypes, I think this is not what you want.
  2. You send the data from one page to the other using models and the POST-data. I will explain this way in detail now, as this seems to be your desired solution. Actually this can be done in a single action if you implement functions to check if there is enough data to render the next page (see the model below).

The following code is not tested, but should give you an idea of how it could be done. Lets start with the model. The model contains the data of all pages. Working with only model across the two input-pages makes things way easier.

class Registration extends CFormModel {
    public $firstName;
    public $lastName;
    //...
    public $gender;
    public $age;
    //...

    public function rules()
    {
        //add all your field-rules here...
    }

    //further functions like attributeLabels(), etc. as needed

    /**
     * Returns the fullname as needed on page two
     */
    public function getFirstname()
    {
        return $this->firstName . ' ' . $this->lastName;
    }

    public function hasValidStepOneData()
    {
        //validate the fields you need to continue to step two and return a boolean value.
        //yii provides this functionality via the validate-function having the abiliy to only
        //only validate certain fields at once. If one of them fails return false, otherwise true.

        //see here: http://www.yiiframework.com/doc/api/1.1/CModel#validate-detail
    }

    public function hasValidStepTwoData()
    {
        //same as above but with values needed for completing step 2
        //return boolean
    }
}

Now to the controller. According to your URLs fromabove it should be like this:

class RegistrationController extends CController {
    public function actionRegSteps()
    {
        $model = new Registration();

        //get the values if there are any
        if (isset($_POST['Registration']) {
            $model->attributes = $_POST['Registration'];
        }

        //decide what to do depending on the data available     
        if ($model->hasValidStepOneData() && $model->hasValidStepTwoData()) {
            //all data needed is present...save the data and redirect to success-page
            //TODO: save data here...
            $model->unsetAttributes();
            $this->render('success');
        } else if ($model->hasValidStepOneData()) {
            //step one is complete...show step2
            $this->render('reg_step2', array('model'=>$model));
        } else {
            //model is still empty...show step 1
            $this->render('reg_step1', array('model'=>$model));
        }
    }
}

The views are quite simple. You have to keep in mind though that you have to add hidden fields on page two to keep the data of step 1. step one only contains input-fields for firstname, lastname and email. Step 2 contains input-fields for password, gender and age and also hidden fields for firstname, lastname and email. The success-view contains no input-fields at all, as the registration-process is completed by then.

Other than this custom-solution, there is a wizard-extension which could come in handy for you. You can find it here: http://www.yiiframework.com/extension/wizard-behavior/ Moreover a similiar solution was already answered here: https://stackoverflow.com/a/3551704/3402681

I provided you the answer above to give you a general insight on how you can handle this. There is no "correct" solution for this. You have to find the one which suits you the best. Hope I could help!

Community
  • 1
  • 1
PLM57
  • 1,256
  • 12
  • 27