I'm new in Yii2 Framework. I want to get Submit Button Name/Value in my Controller/Action.
Following is my code:
Form:
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'admin_document_key_id')->dropDownList(ArrayHelper::map(AdminDocumentKey::find()->all(), 'id', 'key_name'), ['prompt' => 'Select']) ?>
<?= $form->field($model, 'key_value')->textInput(['maxlength' => 255]) ?>
<div class="form-group">
<?php if (Yii::$app->controller->action->id == "create"): ?>
<?= Html::submitButton('Create & Add New', ['class' => 'btn btn-primary']) ?>
<?php endif; ?>
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary', 'value'=>'Create', 'name'=>'submit']) ?>
<?= Html::a('Cancel', ['/admindocumentvalue'], ['class' => 'btn btn-warning']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-info']) ?>
</div>
Controller/Action:
public function actionCreate()
{
$model = new AdminDocumentValue();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
print_r(Yii::$app->request->post());
exit;
return $this->redirect(['index', 'id' => $model->id]);
} else {
return $this->render('create', [
'model' => $model,
]);
}
}
It showing following Output:
Array ( [_csrf] => V0FKc09GclQDbHI1BRVEIR8xOwcjLEFiBSsyGBcZGj4dMWc6JzItbA== [AdminDocumentValue] => Array ( [admin_document_key_id] => 1 [key_value] => Claims ) )
But not showing submit button name and value.
I tried $_POST
& $_REQUEST
as well but still its not working.
Any help would be appreciated.
Thanks.