php - How to get Submit Button Values in Controller/Action Yii2 -
i'm new in yii2 framework. want submit button name/value in controller/action.
following 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 , value.
i tried $_post
& $_request
still not working.
any appreciated.
thanks.
resolved myself changing default yii2 buttons this:
<?= html::submitbutton('create & add new', ['class' => 'btn btn-primary', 'value'=>'create_add', 'name'=>'submit']) ?> <?= html::submitbutton($model->isnewrecord ? 'create' : 'update', ['class' => $model->isnewrecord ? 'btn btn-success' : 'btn btn-primary', 'value'=>'create', 'name'=>'submit']) ?>
then in controller
if (yii::$app->request->post('submit')==='create_add') { // create add } else { // submit }