Form Validate

Hello. I have a big form. So i divided it into 3 parts. User pass through 3 steps to complete form. For example, in the first step user fill last name, first name and so on, in the second step user other information.

I need to validate each step before user goes to next step. Help me?

You can create a model as usual, and use three actions to handle user submits.

Each time, you assign the submitted values, call validate() and check if

there are errors in attributes submit in this step.

$model->attributes = $_POST['MyForm'];

$model->validate(array('attr1','attr2')); //'attr1', 'attr2' are attribute from one step of your form, according to @Rodrigo's reply, this way is better

$errors = $model->getErrors();

if (!empty($errors)){

    //show errors

} else {

    //goto next step


There is also a wizard behavior extension if you want something ready to use to do this.

You can select which attributes are being validated in each step. See CModel::validate.