I am working on yii2
. I am trying to get the submit button
name in my controller. Below is my view
<div class="form-group">
<a class="btn btn-default" onclick="window.history.back()" href="javascript:"><i
class="fa fa-close"></i>
Cancel</a>
<?php if ($model->isNewRecord && in_array(Yii::$app->user->identity->access_level,['admin','manager'])) { ?>
<?= Html::submitButton('Add' ,['class' => 'btn btn-success','name'=>'a']) ?>
<?= Html::submitButton('Add & Send Quotation' ,['class' => 'btn btn-info','name'=>'s']) ?>
<?php } elseif (!$model->isNewRecord && in_array(Yii::$app->user->identity->access_level,['admin'])) {?>
<?= Html::submitButton('Update', ['class' =>'btn btn-warning']) ?>
<?php }elseif (!$model->isNewRecord && in_array(Yii::$app->user->identity->access_level,['editor'])){?>
<?php
if ($model->reqStatus==commonmodelsAccountant::$request_status_titles[0]
||$model->reqStatus==commonmodelsAccountant::$request_status_titles[2]
)
{
echo Html::submitButton('Verified', ['class' =>'btn btn-success','name'=>'v']);
echo Html::submitButton('Not-Verified', ['class' =>'btn btn-danger','name'=>'n']);
}
?>
<?php } elseif (!$model->isNewRecord && in_array(Yii::$app->user->identity->access_level,['manager'])){?>
<?php
if ($model->reqStatus==commonmodelsAccountant::$request_status_titles[3])
{
echo Html::submitButton('Signed',['class' =>'btn btn-primary','name'=>'g']);
}
elseif ($model->reqStatus==commonmodelsAccountant::$request_status_titles[4])
{
echo Html::submitButton('Follow-Up',['class' =>'btn btn-primary','name'=>'r']);
}
else{
echo Html::submitButton('Send Quotation',['class' =>'btn btn-primary','name'=>'q']);
}
?>
<?php } ?>
</div>
In above code there are multiple submit button
each with name
. In my controller I want to get the name of Html::submitButton('Verified', ['class' =>'btn btn-success','name'=>'v']);
this and echo Html::submitButton('Not-Verified', ['class' =>'btn btn-danger','name'=>'n']);
this button.
if (isset($_POST['v'])) //verified
{
$model->load(Yii::$app->request->post());
$model->reqStatus = Accountant::$request_status_titles[1];
$model->callVerified = 1;
$model->clientRef = 'CL-'.uniqid();
if($model->save())
{
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
elseif (isset($_POST['n']))//not-verified
{
$model->load(Yii::$app->request->post());
$model->reqStatus = Accountant::$request_status_titles[2];
if($model->save())
{
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
else
{
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
When I execute it. I am able to see the verified
and not verified
button. But when I click on any of them, it doesn't go to the if (isset($_POST['v']))
or esleif (isset($_POST['n']))
part but hits the else part. This same thing I am doing at another controller which is working perfectly fine.
Update 1
As per scaisEdge
comment I have tried to var_dump($_POST)
and below is the result
array(2) {
["_csrf-backend"]=> string(88) "xS7Ctb2C677HKQJjoBL2SPznK3IHVGUDSn7MGhMs9SigHov36PSI7J9OewzkSJ0AzpBYN0A_KTIlEIZfd1qiYQ=="
["Bookkeeping"]=> array(43) {
["name"]=> string(5) "Laeeq"
["conNumb"]=> string(11) "03464394600"
["email"]=> string(15) "laeeq@gmail.com"
["location"]=> string(12) "Amber Valley"
["reqConcerns"]=> string(22) "UK_limited_partnership"
["workStart"]=> string(21) "PROJECT_START_2_MONTH"
["businessName"]=> string(27) "Retail_consumer_merchandise"
["reqPurpose"]=> string(40) "Select between several bookkeeper quotes"
["bookAssign"]=> string(16) "One_time_project"
["bookkRequire"]=> string(32) "Only local bookkeepers can quote"
["bookWork"]=> string(15) "Annual accounts"
["companyName"]=> string(22) "NONPROFIT_ORGANIZATION"
["turnOver"]=> string(17) "£300,000-600,000"
["info"]=> string(7) "Testing"
["remarks"]=> string(15) "Client Verified"
["annualConf"]=> string(0) ""
["personalTaxRetHrmc"]=> string(0) ""
["mPaySlip"]=> string(0) ""
["mRtiPenRet"]=> string(0) ""
["annualAcc"]=> string(0) ""
["annualCorpTaxRet"]=> string(0) ""
["annualCorpTaxRetHrmc"]=> string(0) ""
["qVatRet"]=> string(0) ""
["qBookMtd"]=> string(0) ""
["insuranceHmrc"]=> string(0) ""
["corpTaxPlan"]=> string(0) ""
["persTaxPlan"]=> string(0) ""
["businessAdvice"]=> string(0) ""
["fedTax"]=> string(0) ""
["provTax"]=> string(0) ""
["invPerM"]=> string(0) ""
["invPerMPrice"]=> string(0) ""
["add1"]=> string(0) ""
["add2"]=> string(0) ""
["add3"]=> string(0) ""
["add4"]=> string(0) ""
["add5"]=> string(0) ""
["add6"]=> string(0) ""
["add7"]=> string(0) ""
["add8"]=> string(0) ""
["add9"]=> string(0) ""
["add10"]=> string(0) ""
["remarks2"]=> string(0) ""
}
}
There is no v
string in the above result.
I must be missing something that I don't know.
Any help would be highly appreciated.
See Question&Answers more detail:
os