Forms etc. close tag

Here http://www.yiiframew…/api/CHtml#form I read

Quote

Generates a form tag. Note, only the open tag is generated. A close tag should be placed manually at the end of the form.

This is not very nice also if you think that an editor with syntax checking could detect than you close a tag ( </form> ) but you didn't open it (because it is opened calling the PHP method). So it seems like this is not the most coherent behaviour.

Is there something we could do here to make this thing nicer?

Maybe a closeForm() method or a generic closeTag('form'), I don't know…

What do you think?

While your point is true, I found other frameworks are doing the same thing as Yii. Creating a function like closeTag()/closeForm() also brings us more trouble than benefit.

But it's good that we can check if we open more than one form inside another or something like this… This could be a nice trick to form open/close check.

Here are my thoughts, feel free to shoot them down. How about create a form object and add to it and then add a function on it to return the html? (please excuse my makeshift syntax for explaining haha)



CForm theform = new CForm(action, method, etc, etc);


theForm.addItem(new FormItem());


theForm.addItem(new FormItem());


theForm.addItem(new FormItem());


echo theForm->getFormHtml();


when getFormHtml() is called it would look in to an internal array of FormItems and begin building the html. one step further… the FormItem could have it's own getHtml().



public function getFormHtml()


{


  String html;


  foreach(FormItem item: FormItemArray)


  {


    html .= item.getHtml();


  }


  return html;


}


which would return your entire form…



<form>


  <input...>


</form>


Quote

While your point is true, I found other frameworks are doing the same thing as Yii. Creating a function like closeTag()/closeForm() also brings us more trouble than benefit.

Yes, there would be no added benefit. The developer would still need to remember to call that method, and calling a method will add some overhead.

For static forms (used in most cases), using CForm is a bit too restrict as a form is often composed by many complex design elements. It is less intuitive to designers.

That said, using CForm is good for building dynamic forms (form input fields are determined according to some data). So we may consider implementing such feature in future (AFAIK, Symfony has this).