You can just change the name. You can do this like this echo $form->textFieldBlock($model,'name',array('name' => 'x["name"]')
or whatever you want. You could also create a class (widget) with does this for your.
class MyActiveForm extends CActiveForm {
public function hiddenField($model, $attribute, $htmlOptions = array()) {
if(isset($htmlOptions['shortName'])) {
$htmlOptions['name'] = $htmlOptions['shortName'] . "[".$attribute."]";
unset($htmlOptions['shortName']);
}
return parent::hiddenField($model, $attribute, $htmlOptions);
}
}
You change CActiveFrom
from the widget to MyActiveForm
. Then use $form->textFieldBlock($model,'name',array('shortName' => 'x')
. You could also change the above code to always change to a shortname without the htmlOptions
. So that it is always x. However you could not have two form at once in this case. Benifit is that you would not need to add array('shortName' => 'x')
to all of them, but just change CActiveFrom
to MyActiveForm
. So that would save you time, but cost your flexibility (with you might need later on maybe).
You have to create a function offcourse for every input field you want to use from ActiveRecord. The name of the element would become x['name']
In the controller you could simply do $model->attributes = $_POST['x']
.