2 Questions for forms

Hello community

I have two questions to forms in yii.

First Question: Whats the best practice to have a Form in each page side on the sidebar (e.g. Registration Form), this form should be shown in all controller sites etc. and it should validated etc with ajax. How can i solve this problem in best way in yii and with CFormModel and CActiveRecord?

Second Question: Unlike in Zend in yii it hasnt a Form Decorator. So whats the best practice to use a CFormModel or CActiveModel in two (or more) views (in different controllers) without to make for all always a _form.php view? How can I solve this problem to make the DRY princip? I dont want to make in each controller same form html code for the same form.

I hope very for helping to solve this two problems.

Thank you.


For reuse part of views you can create widgets.

Those are simply class in components that extends CWidget.

You have to implement the function run, and you can render views that lies in component/views, see the documentation about this.

For a widget displayed in all pages, you can include this widget in views/layout/main.php


Thank you for your idea. I will use it!

Maybe you have also a idea about my other question: how can i handle this form in this widget? It submited value must be go to a controller? and how can i do this with ajax solution? This widget-form will be shown in all pages so it should work in all controller action pages etc.

Thank you for helping.