Readonly form

Hello all,

What are some suggestions if I want to create a form with two separate "modes", View and Edit.

In View Mode the elements should appear as normal text (not textfields or select boxes or any other typical form element) and in Edit mode, well, edit mode is easy, since the form behaves in Edit mode by default.

My intention is to use the following procedure:

In my controller:


$myForm = new MyForm;

$myForm->attributes = $savedData;   // to populate the form fields

$this->render('formFile', array('myForm' => $myForm, 'mode' => 'view));

Then, in my formFile view file:

Use the $mode var to render the form fields as normal text (not form elements) and hide the submit/reset buttons. Maybe even provide an “Edit” button to redirect back to the controller and turn the ‘mode’ option to ‘edit’ so I can edit the displayed form.

Any ideas if this functionality can be implemented in a better way?

Thanks.

Stratos

PS: Why I want this? The Yii app I’m building is using restfull access to get to the models. Therefore I cannot use CActiveRecord to define my models. So I am creating Form models to display and edit my models. All the necessary REST operations are done by me in the controller.