Код: Выделить всё
<?php foreach ($models as $model): ?>
<?php $form = ActiveForm::begin([
'id' => 'form-'.$i,
'action' => Url::to(['reshuffle/stepcreate']),
'enableAjaxValidation' => true,
'validateOnChange' => false,
'validateOnBlur' => false,
'validateOnSubmit' => true,
]); ?>
<h4><?= $model->step_name ?></h4>
<?= $form->field($model, 'step_note')->textInput()->label()->error(['tag' => 'span']) ?>
<?= $form->field($model,'status')->radioList(ReshuffleSteps::getStatusArray())->label(false)->error(['tag' => 'span']) ?>
<?= Html::activeHiddenInput($model, 'belong_id') ?>
<?= Html::activeHiddenInput($model, 'step_id') ?>
<?= Html::activeHiddenInput($model, 'reshuffle_type') ?>
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-primary']) ?>
<?php ActiveForm::end(); ?>
<?php $i++; ?>
<?php endforeach ?>
Код: Выделить всё
public function rules()
{
return [
[['reshuffle_type', 'step_id', 'status', 'step_note','belong_id'], 'required'],
[['reshuffle_type', 'step_id', 'status', 'user_id','belong_id'], 'integer'],
['step_note', 'string','min' => 5, 'max' => 555],
['user_id', 'default', 'value' => Yii::$app->user->identity->id],
['belong_id', function($attribute, $params){
if(something true) $this->addError($attribute, 'Ошибка');
}],
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'belong_id' => 'Сотрудник',
'reshuffle_type' => 'Тип перестановки',
'step_id' => 'Шаг',
'status' => 'Статус',
'step_note' => 'Заметка',
'user_id' => 'Пользователь',
'step_name' => 'Название шага',
];
}
Код: Выделить всё
public function actionStepcreate()
{
$model = new ReshuffleSteps();
if ($model->load(Yii::$app->request->post(),"")) {
$validateResult = ActiveForm::validate($model);
if ($validateResult) {
Yii::$app->response->format = Response::FORMAT_JSON;
return $validateResult;
} else {
$model->save(false);
return $this->redirect(Yii::$app->request->referrer);
}
}
}