Since I don’t want to (can’t) use model in generation of a form (explained here) and therefore since I can’t take advantages of using CForm, CActiveForm or Form Builder, I wrote a simple (test version yet) form with using CHtml:
I tried to use old-school, not-object-oriented, not yii-aware approach of looking what is inside $_POST array:
echo('name='.$_POST['name'].'<br /><br />');
But this failed with PHP error saying: "Undefined index: name".
What am I missing?
Both documentation (guide / cookbook) and forum post seems to be very focused on building forms with using models and I can’t find anything that would easily explain how to build and process forms generated with pure CHtml approach, like in above example.
I’ve noticed that I was getting “Undefined index: name” error, because I had error_reporting = E_ALL | E_STRICT set in php.ini. After reverting it to error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED all went smudgily. After reverting it back to what it was (most strict error reporting mode) I had to change above line to:
if (isset($_POST['name'])) echo('name='.$_POST['name'].'<br /><br />');
But then again, question in post title remains. Is using good, old $_POST array the only (the best) solution for processing forms generated with using CHtml?
I am using it all the time when I require some specific features on my forms (not those automated by Yii)
There are plenty of ways to do so but, why not using the good Yii approach with models but applying them to what we want? -My english s*ks… let me code…
-on the view:
echo CHtml::textField(‘FORMNAME[fieldname]’);
-on the controller:
if(isset($_POST[‘FORMNAME’]))
In this way I just need to check once for the variable and create objects for validation, save, update… just like CActiveRecord does…