I notice there is no class in Yii2 for creating html-forms. Forms are generated by all that exists in Yii. They are HTML-class (see the getInputId() method for example), CForm in Yii1 and may be so on. So there is no only class in yii which is intended for generating html-forms. CModel-class in Yii can’t be the necessary class because of it is for validating data only. New independent class for form generating needed. Models, CForms, helpers and other clases can be deligated in this class. Developers could extend this class for their own needs. All logic for form generating must be inside this class.
$FormManager=new FormManager('formName');
$FormManager->fillFormByModel($model); //Model which validates data is used to get needed data to generate form
if (!$FormManager->isError())
{
$FormManager->MainAction();
}
else
{
$this->render('myview', array('FormManager'=>$FormManager));
}
//myview.php
echo $FormManager->beginForm();
echo $FormManager->errorSummary();
echo $FormManager->generateFullForm();
echo $FormManager->endForm();
or
//myview.php
echo $FormManager->beginForm();
echo $FormManager->errorSummary();
echo $FormManager->activeLabel('username');
echo $FormManager->activeTextField('username');
echo '<br />';
echo $FormManager->activeLabel('password');
echo $FormManager->activePasswordField('password');
echo '<br />';
echo $FormManager->submitButton('Enter');
echo $FormManager->endForm();
What do you think about this? Is it possible to create new class and give it the independent functionality?