goose
goose

Reputation: 2660

What alternatives are there to Yii active form?

I wish to build a form that does not create/update any active records. An example of such a form would be a search filter using check boxes for the user to select which categories to apply to the search.

Everything I read about forms in Yii is centred around the CActiveForm class. What is the Yii way to build forms that don't use active records?

Upvotes: 2

Views: 442

Answers (2)

Michael Härtl
Michael Härtl

Reputation: 8607

If you want to embrace Yii's convenient form handling, you should use CActiveForm. It does not require CActiveRecord. But it always requires a model for your form data - which is a good thing, because this will keep the validation rules out of your view files. Instead of a CActiveRecord you could also build a simple model class from CFormModel.

class SomeForm extends CFormModel
{
    public $name;
    public $email;
    public function rules()
    {
        return array(
            array('name,email','required'),
            array('email','email'),
        );
    }
}

Upvotes: 2

ernie
ernie

Reputation: 6356

Check the docs of the CHtml class. While it contains all the active* method, there are plain form methods in there as well, such as checkBox() or checkBoxList() that sound like what you're looking for.

Upvotes: 1

Related Questions