Designing complex form (having 35 fields)

i have started working with Yii from sometime now and alot of my time & effort is going into arranging the form elements in the proper order & format, in good layout. Its so tedious & time consuming doing completely in code.

I have so many complex forms in my project, having even 15 to 45 fields in one form.

Lets take a form: there are 35 fields: textbox, dropdown, textarea, date/time, radio & also a CGridView, all there.

Now i have to arrange them in proper sequence: writing the <div class=""> tags all over the place & so nested.

There are multiple sections, single & multiple columns.


Normally the size of the textbox, dropdown, etc are not the one we set in the database table,

So setting the right size/width to the elements: editing the htmloptions (so many of them) and for some we have to change it many time so as to suit the design.

i was thinking is there any way around to layout the form elements easily.

i thought for CForm but that too didn’t the process any easy. Reuseability is not my concern right now.

hopefully u people can well imagine how tidious it becomes to make such form ready for display.

i am really in need of something to save this Time & EFFORT.

Plz suggest.

You can change the structure of the Gii generated form.

Take a look at this at the paragraph "extending gii"

well yes some basic structure can be done there.

you mean storing the layout settings such as width height etc? what about using CSS? or store it in a "settings" model?

Yeah right the width, height, row, cols, etc. But also to set the right input type for each field.

i think by creating custom form template for gii we could generate a more accurate form, by parsing the model attribute names, labels & size. it is already reading that for the form generation.

Bydefault all the fields generated are textfields, we have to replace some to dropdown, textarea,…

what we can do in the custom template is:

  • to put dropdown, check if attribute name ending with ‘_id’, if so write the dropdown code. usually foreign key attribute names ends like that and used dropdowns to select (may not be for some).

  • to put textarea, check the size if say > 70 write the textarea code

and so on.

or better to check one thing only: attribute labels, suffix temporarily to something we can easily replace all, specifying the input type.


  • for dropdown: ~drop

  • for textarea: ~tarea

  • for checkbox: ~check

… & so on

what do u think?

all this is to minimize the effort we have to put on the auto-generated form afterwards to set it right.

I had too a modified version of gii.

What i do is:

  • change the main structure to one I like more

  • automatically generate dropdown looking if there are relations on this field

  • automatically generate dropdown if the field is an enum

  • automatically generate checkbox if is int(1)

I also edited the generator of view and admin, in order to:

  • show the field description for the related fields

  • show yes/no for int(1) (boolean)

this is a big help. By the way keep in mind that you will never generate a perfect form, you will always have to correct some detail, so choose a good treshold between extending gii and manual editing (like, not use 100 hour for create a complex gii in order to avoid 10h of editing).

Remember that Yii always grows, gii follow the framework but your extension no!!! Sooner or later you will have to redo this extension, and the more deeper you are going, the more paifull will be following the news of the framework.

yes u r right. i am aware of this thing. i just want to make it somewhat easier to work with the generated form.

thanks for ur suggestion.