I have data that is being passed through an POST method. However when I try to get some data out of it and set it to a session variable, there is no data in it yet when I print_R($_POST) I see there is Data in it.
This is What I'm getting when I print_r() the POST data.
Array (
[_csrf] => nXRvIHfHWeao64YBdwcdFJa3fz-KShIyAuHDNtKQqhCkDRdwErUqkOrSyHQQamtR5cBHWc57QUNq16hflaftKQ==
[LoginForm] => Array (
[compayname] =>Termite Soup
[username] => Jim.Bot
[password] => 123456
[url] =>
)
[login-button] =>
)
This is what I've tried.
This is the form where form is being filled.
<?php $form = ActiveForm::begin([
'id' => 'login-form',
'layout' => 'horizontal',
'fieldConfig' => [
'template' => "{label}\n<div class=\"col-lg-10\">{input}
</div>\n<div class=\"col-lg-8\">{error}</div>",
'labelOptions' => ['class' => 'col-lg-3 control-label'],
],
]);
?>
<?php echo $form->field($model,
'compayname')>dropDownList(['GF_TB_TNT' => 'GF-TNT',
'Chicken Soup' =>'Dog Soup',
'Termite Soup' =>'Termite Soup',
],
['prompt'=>'Select Company']); ?>
<?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<?= $form->field($model, 'url')->hiddenInput()->label(''); ?>
<div class="row">
<div class="btn-group">
<!-- <div class="col-md-2">
</div> -->
<div class="col-md-6">
<?= Html::submitButton('Login', ['class' => 'btn btn-primary pull-left', 'name' => 'login-button','style'=>'font-size: 15px;']) ?>
</div>
Getting the data and setting it to a Session Variable
if (Yii::$app->request->post()) {
$companyname = Yii::$app->request->post('compayname');
}
I want to set the companyname in the POST to a session Variable
What you can do is
foreach (Yii::$app->request->post('LoginForm') as $field) {
// some logic
}
Also I see a mistake in compayname. A "n" is missing in the word. But you can access it's value by Yii::$app->request->post('LoginForm')['compayname'];
You can shortly get this.
$arr = [];
foreach ($_POST as $param) {
if (is_array($param)) {
foreach ($param as $name) {
if ($name == 'LoginForm') {
array_push($arr, $name);
}
}
} else {
}
}
And you can figure out how the data is structured using var_dump
var_dump($arr);
Related
My function inside controller is as follows:
public function actionProjects($id)
{
$model = $this->findModel($id);
$projects = Project::find()->all();
$projectIds = Yii::$app->request->post('projects');
if (Yii::$app->request->isPost) {
Yii::$app->session->setFlash('success');
$model->unlinkAll('projects');
if ($projectIds) {
foreach ($projectIds as $projectId) {
$project = Project::findOne(abs((int)$projectId));
if ($project) {
$model->link('projects', $project);
}
}
}
}
print_r($projectIds);
return $this->render('projects', ['projects' => $projects, 'model' => $model]);
}
My view is as follows:
<?php
...
function sortArray($a, $b)
{
return strcmp($a, $b);
}
$projects = ArrayHelper::map($projects, 'id', 'title');
usort($projects, 'sortArray');
?>
<div class="application-create x_panel">
<div class="x_title"><h3><?= Html::encode($this->title) ?></h3></div>
<div class="x_content">
<?php $form = ActiveForm::begin(); ?>
<div class="form-group">
<?= Select2::widget([
'name' => 'projects[]',
'options' => ['placeholder' => 'Выберите проект...'],
'language' => 'ru',
'value' => array_keys(ArrayHelper::map($model->projects, 'id', 'title')),
'data' => $projects,
'pluginOptions' => [
'allowClear' => true,
'multiple' => true
],
]) ?>
</div>
<div class="form-group">
<?= Html::submitButton('Обновить', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end() ?>
</div>
</div>
When I select single or multiple items from select2, and click update button - this code:
$projectIds = Yii::$app->request->post('projects');
posts array like this: Array ( [0] => 0 [1] => 1 [2] => 2 )
the data sent to the server is the array of indexes of items and not actual indexes (primary keys) from the table. (I have 3 items in db table - their indexes are 5,6 and 7)
How to sent primary keys of selected items? I cannot find hidden rat that causes my problem. It seems that everything is correct in code. But actually not.
The problem is in the usort() call. That function removes the indexes in your $projects array. You have to use uasort() instead which is designed to maintain indexes in associative arrays.
so I have a form that contains a hidden input.
<?= $this->Form->create(null, [ 'class' => '', 'templates' => 'Inspinia.form_basic']) ?>
<?php
echo $this->Form->control('name');
echo $this->Form->control('description', ['type' => 'text']);
echo $this->Form->control('chart_type', [ 'options' => $this->App->availableCharts() ] );
echo $this->Form->control('frequency', [ 'options' => ['monthly' => 'Monthly','quarterly'=>'Quarterly','snapshot' =>'Snapshot','monthly/quarterly' => 'Monthly/Quarterly'] ] );
echo $this->Form->control('public', [ 'options' => ['1' => 'Public','0' => 'Private'] ] );
// $this->Form->unlockField('deleted');
echo $this->Form->hidden('deleted',['value' => 0]);
?>
<?= $this->Form->button(__('Save'), ['class' => 'btn btn-sm btn-primary pull-right m-t-n-xs']) ?>
<?= $this->Form->end() ?>
Whenever I try to submit the form, it throws me this error
Missing field 'deleted' in POST data
I know I can bypass this by just doing
$this->Form->unlockField('deleted');
but I don't want to bypass the security component in Cakephp, so is there any other way I can get CakePhp to allow me to submit this hidden field?
this is my controller nothing too much but here just in case you guys are wondering
public function test() {
if ($this->request->is('post')) {
debug($this->request->data);
}
}
It should like below
<?php
echo $this->Form->input('nameoffield',array('type'=>'hidden'));
?>
or passing a hidden value
<?php
$hidden_value = 0;
echo $this->Form->input('nameoffield',array('type'=>'hidden','value' => $hidden_value));
?>
I want to use dynamic form widget (wbraganca). I tried it using the tutorial by 'doingItEasy' channel & also by github. And wrote following code :
controller code -
public function actionCreate()
{
$model = new Vendors();
$modelsSubCat = [new BusinessSubCategories];
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$modelsSubCat = Model::createMultiple(BusinessSubCategories::classname());
Model::loadMultiple($modelsSubCat, Yii::$app->request->post());
// validate all models
$valid = $model->validate();
$valid = Model::validateMultiple($modelsSubCat) && $valid;
$modelsSubCat = Model::createMultiple(BusinessSubCategories::classname());
if ($valid) {
$transaction = \Yii::$app->db->beginTransaction();
try {
if ($flag = $model->save(false)) {
foreach ($modelsSubCat as $modelSubCat) {
$model->ven_sub_category_id = $modelSubCat->bsc_id;
if (! ($flag = $modelSubCat->save(false))) {
$transaction->rollBack();
break;
}
}
}
if ($flag) {
$transaction->commit();
return $this->redirect(['view', 'id' => $model->ven_id]);
}
} catch (Exception $e) {
$transaction->rollBack();
}
}
} else {
return $this->render('create', [
'model' => $model,
'modelsSubCat' => (empty($modelsSubCat)) ? [new BusinessSubCategories] : $modelsSubCat
]);
}
}
'_form.php' code -
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use wbraganca\dynamicform\DynamicFormWidget;
?>
<div class="vendors-form">
<?php $form = ActiveForm::begin(['id' => 'dynamic-form']); ?>
<?= $form->field($model, 'ven_company_name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_main_category_id')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_sub_category_id')->textInput() ?>
<div class="row">
<div class="panel panel-default">
<div class="panel-body">
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 4, // the maximum times, an element can be cloned (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $modelsSubCat[0],
'formId' => 'dynamic-form',
'formFields' => [
// 'bsc_id',
'bsc_name',
'bsc_image',
'bsc_description',
'bmc_id',
],
]); ?>
<div class="container-items"><!-- widgetContainer -->
<?php foreach ($modelsSubCat as $i => $modelSubCat): ?>
<div class="item panel panel-default"><!-- widgetBody -->
<div class="panel-heading">
<h3 class="panel-title pull-left">Sub Categories</h3>
<div class="pull-right">
<button type="button" class="add-item btn btn-success btn-xs"><i class="glyphicon glyphicon-plus"></i></button>
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
// necessary for update action.
if (! $modelSubCat->isNewRecord) {
echo Html::activeHiddenInput($modelSubCat, "[{$i}]id");
}
?>
<?= $form->field($modelSubCat, "[{$i}]bsc_name")->textInput(['maxlength' => true]) ?>
<div class="row">
<div class="col-sm-6">
<?= $form->field($modelSubCat, "[{$i}]bsc_image")->fileInput(); ?>
</div>
<div class="col-sm-6">
<?= $form->field($modelSubCat, "[{$i}]bsc_description")->textInput(['maxlength' => true]) ?>
</div>
</div><!-- .row -->
</div>
</div>
<?php endforeach; ?>
</div>
<?php DynamicFormWidget::end(); ?>
</div>
</div>
<?= $form->field($model, 'ven_services_offered')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_business_logo')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_company_descr')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_established_date')->textInput() ?>
<?= $form->field($model, 'ven_noof_emp')->textInput() ?>
<?= $form->field($model, 'ven_branches_loc')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_market_area')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_website')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_specialized_in')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_contact_no')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_email_id')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_address')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_country_id')->textInput() ?>
<?= $form->field($model, 'ven_state_id')->textInput() ?>
<?= $form->field($model, 'ven_city_id')->textInput() ?>
<?= $form->field($model, 'ven_location_id')->textInput() ?>
<?= $form->field($model, 'ven_zip')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'ven_contact_person_id')->textInput() ?>
<?= $form->field($model, 'ven_verified')->dropDownList([ 'Y' => 'Y', 'N' => 'N', ], ['prompt' => '']) ?>
<?= $form->field($model, 'ven_created')->textInput() ?>
<?= $form->field($model, 'ven_updated')->textInput() ?>
<?= $form->field($model, 'ven_deleted')->dropDownList([ 'Y' => 'Y', 'N' => 'N', ], ['prompt' => '']) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
<script type="text/javascript">
$(".dynamicform_wrapper").on("beforeInsert", function(e, item) {
console.log("beforeInsert");
});
$(".dynamicform_wrapper").on("afterInsert", function(e, item) {
console.log("afterInsert");
});
$(".dynamicform_wrapper").on("beforeDelete", function(e, item) {
if (! confirm("Are you sure you want to delete this item?")) {
return false;
}
return true;
});
$(".dynamicform_wrapper").on("afterDelete", function(e) {
console.log("Deleted item!");
});
$(".dynamicform_wrapper").on("limitReached", function(e, item) {
alert("Limit reached");
});
</script>
'create.php' code -
<?php
use yii\helpers\Html;
/* #var $this yii\web\View */
/* #var $model backend\models\Vendors */
$this->title = Yii::t('app', 'Create Vendors');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Vendors'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="vendors-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
'modelsSubCat' => $modelsSubCat
]) ?>
</div>
But What happens is that the add/remove button is not working. I'm showing it's screenshot - Screenshot with Add/remove buttons
1)first add
$form = ActiveForm::begin([
'options' => [
'enctype' => 'multipart/form-data',
'id' => 'dynamic-form'
]
]);
instead your
2) delete 'bmc_id' from attributes of dynamic form or add textinput to dynamic form with bmc_id column
3) check if exist your model Model (...Model::loadMultiple($modelsSubCat, Yii::$app->request->post());)
I tried, but i can't reproduce this issue here. Can you try fix the following lines and see if the problem was there?
You are not closing the <div class="row"> after the dynamic form.
This could mess up the html code.
In your formFields, you don't need to add the 'bmc_id' if the
model have one. Remove it. By the way, you are using:
Html::activeHiddenInput($modelSubCat, "[{$i}]id");
Make sure this is the correct name of the attribute.
Non-related with your issue, you have a second:
$modelsSubCat = Model::createMultiple(BusinessSubCategories::classname());
After the loadMultiple method, making it useless.
EDIT
Just occurred to me: by any chance you have more than one DynamicForm in the same view? Or the code is the same as you posted?
I have been searching for the solution for the past few days but i could not get the correct solution include posting it to stackoverflow before Submitting Button Value to Controller but fail to post the value, but i decided to submit it again because the problem has changed since i already know the error.
I want to post multiple submit button to controller in yii2, at first i can get the submitbutton value from $_POST['chosen'] in controller if the code looks like (below):
<?php $form =ActiveForm::begin() ?>
<hr>
<div class="row">
<div style="float:left" >
<?= Html::submitButton('Add Row', [ 'name' => 'chosen', 'value' => 'addmore', 'class' => 'btn btn-info']) ?>
</div>
<div style="float:right" >
<?= Html::submitButton('Next Page', ['class' => 'btn btn-primary', 'name' => 'chosen', 'value' => 'nextpage']) ?>
</div>
</div>
<?php ActiveForm::end()?>
but when i add my function to generate a div, i could not get the $_POST['chosen'] anymore, but i still can get the $model object in controller. the function (addRelationForm) is used to generate div object dynamically so i can submit undertermined-size of array to the controlleer. i could add dynamically the div by pressing add row button.
<?php
use kartik\widgets\RangeInput;
use yii\app\clientScript;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
use frontend\models\relation;
$this->registerJsFile('http://code.jquery.com/jquery-2.1.4.min.js');
function addRelationForm($form, $item, $i){
return '<div class="col-md-12" id=\'r_'.($i).'\'>
<div class="form-group col-md-12">
<label> Friend ' . ($i + 1) . '</label>'.
$form->field($item, "[$i]user_friend_id") .
'<label> Closeness to you </label>
<div class="form-inline"> ' .
$form->field($item, "[$i]closeness")->widget(RangeInput::classname(), [
'options' => ['placeholder' => 'Rate (1 - 5)...'],
'html5Options' => [
'min' => 1, 'max' => 5,
'width' => '75%',
'addon' => ['append' => ['content' => '<i class="glyphicon glyphicon-star"></i>']]
]])->label(false).
'</div> '.
'<div class="form-inline" >
I know this person as a friend for approximately (in year) '.
$form->field($item, "[$i]known_for")->textInput(["type" => "number", "placeholder" => '(in year)'])->label(false).
'</div></div></div>';
}
?>
<h1>Friendship Survey</h1>
<p> Introverted the space below, list up to ten of your closest friends that are currently in Econs/ Math and Econs; a minimum of 5 is compulsory. *Please select their full names from the dropdown list provided. Also, please select on the scale how close you are to each friend. 1Note the incentives for this section </p>
<?php $form =ActiveForm::begin() ?>
<?php foreach ($items as $i => $item) {
echo addRelationForm($form ,$item, $i);
}
?>
<hr>
<div class="row">
<div style="float:left" >
<?= Html::submitButton('Add Row', [ 'name' => 'chosen', 'value' => 'addmore', 'class' => 'btn btn-info']) ?>
</div>
<div style="float:right" >
<?= Html::submitButton('Next Page', ['class' => 'btn btn-primary', 'name' => 'chosen', 'value' => 'nextpage']) ?>
</div>
</div>
<?php ActiveForm::end()?>
<?php
$this->registerJsFile('/advanced/frontend/web/js/partone-two.js');
?>
my controller looks like this:
public function actionTwo(){
if(\Yii::$app->user->isGuest){
$this->goHome();
}
$models = [];
var_dump($_POST);
Yii::trace("esting" .empty($_POST['chosen']));
for($i = 0; $i < 5 ; $i++){
$models[$i] = new RelationForm();
}
if(!empty($_POST['add'])){
if('addmore' == $_POST['add']){
Model::loadMultiple($models, Yii::$app->request->post('items'));
$model = new RelationForm();
array_push($models, $model);
return $this->render('two', ['items' => $models]);
}
}
if (Model::loadMultiple($models, Yii::$app->request->post()) )
{
$count = 0;
for($i = 0 ; $i < count($models); $i++){
if(!$models[$i]->validate()){
if($models[$i]->hasErrors()){
Yii::trace( Html::errorSummary($models[$i] ));
}
return $this->render('two', ['items' => $models]);
}
}
for($i = 0 ; $i < count($models); $i++){
if(!$models[$i]->store()){
return $this->render('two', ['items' => $models]);
}
}
Yii::$app->session->setFlash('success', "Processed {$count} records successfully.");
return $this->redirect('three', ['items' => $models]);// redirect to your next desired page
}
else {
Yii::trace("Render");
return $this->render('two', array('items' => $models));
}
return null;
}
Instead of <?= Html::submitButton('Add Row', [ 'name' => 'chosen', 'value' => 'addmore', 'class' => 'btn btn-info']) ?> which create <button type="submit" ... >Submit</button> use submitInput($label = 'Submit', $options = []) which create <input type="submit" name="chosen" value="addmore" class="btn btn-info">
Then in controller: $var = \Yii::$app->request->post('chosen');
you can check if variable is empty: empty($var) (different names for each submitInput with no values) or isset && $var === 'your_value' (same name, but diff. value in submitInput - not tested if it`s working)
I want to get multiplie instance of the same model in my controller. I saw this wiki for Yii 1.1 and tried like that but in my code only last instance in form was acceble from controller my code is here (I commented code with error and variable values):
$model = new Person(['scenario' => 'create_update']);
$contractDate = new DatePart(); // DatePart is my own class
$contractExpirationDate = new DatePart(); // DatePart is my own class
if ($model->load(Yii::$app->request->post()) &&
$contractDate->load(Yii::$app->request->post()) &&
$contractExpirationDate->load(Yii::$app->request->post())){
Yii::info(Yii::$app->request->post(),'test'); // only one instance of Person and one instance of DatePart are available here
Yii::info($_POST['DatePart'],'test'); // only last instance of DatePart (contractExpirationDate in html form) is available here
Yii::info($_POST['DatePart'][0],'test'); // Error: Undefined offset: 0
Yii::info($_POST['DatePart'][1],'test'); // Error: Undefined offset: 1
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
'contractDate' => $contractDate,
'contractExpirationDate' => $contractExpirationDate,
]);
}
It is my form view in _form.php:
<?php
use yii\helpers\Html;
//use yii\widgets\ActiveForm;
use kartik\widgets\ActiveForm;
use common\models\DataOperations;
/* #var $this yii\web\View */
/* #var $model app\models\Person */
/* #var $contractDate backend\viewModels\DatePart */
/* #var $contractExpirationDate backend\viewModels\DatePart */
/* #var $form yii\widgets\ActiveForm */
?>
<div class="user-form">
<?php
$form = kartik\widgets\ActiveForm::begin(
[
'id' => $model->isNewRecord ? 'user-form-create' : 'user-form-update',
'type' => ActiveForm::TYPE_VERTICAL,
//'enableAjaxValidation' => true,
'fieldConfig' => [
//'autoPlaceholder'=>true
]
]);
?>
<?= $form->field($model, 'name')->textInput(['maxlength' => 60]) ?>
<?= $form->field($model, 'family')->textInput(['maxlength' => 60]) ?>
<?= $form->field($model, 'mobile')->textInput() ?>
<?= $form->field($contractDate, 'year')->textInput() ?>
<?= $form->field($contractDate, 'month')->textInput() ?>
<?= $form->field($contractDate, 'day')->textInput() ?>
<?= $form->field($contractExpirationDate, 'year')->textInput() ?>
<?= $form->field($contractExpirationDate, 'month')->textInput() ?>
<?= $form->field($contractExpirationDate, 'day')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
It is log result for:
Yii::info(Yii::$app->request->post(),'test')
in debugger as you seen only last DatePart available but I have two DatePart model instance (contractDate and contractExpirationDate):
[
'_csrf' => 'Vl81R0ZvMk1hD1oELT9aDzkIe3EPHFgiIBJTBhA9RD8GbFM.AhlVBw==',
'Person' => [
'name' => 'test name',
'family' => 'test family',
'mobile' => '09121212123',
],
'DatePart' => [
'year' => '2015',
'month' => 'Jun',
'day' => 'Mon',
],
]
Controller:
$model = new Person(['scenario' => 'create_update']);
$dates = [
'contractDate' => new DatePart(),
'contractExpirationDate' => new DatePart()
];
if ($model->load(Yii::$app->request->post())) {
if (Model::loadMultiple($dates, Yii::$app->request->post()) && Model::validateMultiple($dates)) {
foreach ($dates as $date) {
$date->save();
}
// or
$contractDate = $dates['contractDate'];
$contractExpirationDate = $dates['contractExpirationDate'];
// ...... some logic
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}
}
else {
return $this->render('create', [
'model' => $model,
'dates' => $dates
]);
}
View Form:
<?= $form->field($dates, '[contractDate]year')->textInput() ?>
<?= $form->field($dates, '[contractDate]month')->textInput() ?>
<?= $form->field($dates, '[contractDate]day')->textInput() ?>
<?= $form->field($dates, '[contractExpirationDate]year')->textInput() ?>
<?= $form->field($dates, '[contractExpirationDate]month')->textInput() ?>
<?= $form->field($dates, '[contractExpirationDate]day')->textInput() ?>
To complement b24 answer.
// In View Form add foreach:
<?php foreach ($dates as $index => $date): ?>
<?= $form->field($date, '[contractDate]year')->textInput() ?>
<?= $form->field($date, '[contractDate]month')->textInput() ?>
<?= $form->field($date, '[contractDate]day')->textInput() ?>
<?= $form->field($date, '[contractExpirationDate]year')->textInput() ?>
<?= $form->field($date, '[contractExpirationDate]month')->textInput() ?>
<?= $form->field($date, '[contractExpirationDate]day')->textInput() ?>
<?php endforeach; ?>
// - or - add index
<?= $form->field($dates['contractDate'], '[contractDate]year')->textInput() ?>
<?= $form->field($dates['contractDate'], '[contractDate]month')->textInput() ?>
<?= $form->field($dates['contractDate'], '[contractDate]day')->textInput() ?>
<?= $form->field($dates['contractExpirationDate'], '[contractExpirationDate]year')->textInput() ?>
<?= $form->field($dates['contractExpirationDate'], '[contractExpirationDate]month')->textInput() ?>
<?= $form->field($dates['contractExpirationDate'], '[contractExpirationDate]day')->textInput() ?>
This can be is solution for this problem :
http://www.yiiframework.com/forum/index.php/topic/53935-solved-subforms/page__p__248184#entry248184