I have an issue that I have to retrieve the PHP Variable from the Grid to the Modal.
The situation is like this:
This is one of my columns which I name as 'flag', there is a condition state in the column that when the row contains 'test', the column will output a button.
[
'headerOptions' => ['style' => 'text-align: center; width: 3%; vertical-align: middle;'],
'contentOptions' => ['style' => 'text-align: center;'],
'attribute'=>'flag',
'format'=>'raw',
'value'=>function($model){
// $result = $model->flag?
$getCode = $model->customer_code;
$getBillID = CustomerBillingParty::find()->select('id')->where(['customer_code'=>$getCode])->scalar();
$getMain = CustomerBillingParty::find()->select('to_main')->where(['id'=>$getBillID])->scalar();
$getbillto = CustomerBillingParty::find()->select('bill_to')->where(['id'=>$getBillID])->scalar();
$getbilladdress = CustomerBillingParty::find()->select('billing_address')->where(['id'=>$getBillID])->scalar();
if($model->change_billing_party =="TEST")
{
$result= HTML::SubmitButton('ALERT',['name'=>'fname','value'=>$getCode,'id'=>'btnclickvalue','bill_address'=>$getbilladdress,'bill_to'=>$getbillto,'BillID'=>$getBillID,'To_Main'=>$getMain,'sspc_ref'=>$getSSPC,'customer_code'=>$getCode,'class'=>'twelve btn-new-billing'],['data-method' =>'POST']);
}
else{
$result="N/A";
}
return $result;
}
],
The button contains a class that will output a Modal when clicked. This is performed by using javascript/jquery to show the modal.
$(document).on('click','.btn-new-billing',function(){
$('#modal-new-billingParty').modal('show');
$('#customerbillingparty-customer_code').val($(this).attr('customer_code'));
$('#customerbillingparty-to_main').val($(this).attr('to_main'));
$('#customerbillingparty-bill_to').val($(this).attr('bill_to'));
$('#customerbillingparty-billing_address').val($(this).attr('bill_address'));
//The 4 lines above are used to populate the form inside the Modal based on the row on the Grid.
});
The button also contains a set of attributes that carries a value to be used inside of a Modal.
I need to pass the value of the button when clicked in the Modal.
This is the modal code (The modal code is coded above the GRID): The modal is pop out when the button is clicked using the javascript/jquery.
Modal::begin([
'header' => 'Billing Party',
'id'=>'modal-new-billingParty',
'size'=>'modal-lg',
]);
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_POST['fname'];
if (empty($name)) {
echo "EMPTY";
} else {
echo "HELOOOOOOOOOOOOOOOOO";
}
}
//echo "HELLOOOOO";
echo '<div class="customer-billing-party-form">';
$form = ActiveForm::begin([
'action' =>['customer-billing-party/create']
]);
echo $form->field($modelBill, 'customer_code')->textInput(['maxlength' => true,'readonly'=>true]);
echo $form->field($modelBill, 'to_main')->dropDownList(
ArrayHelper::map(CustomerBillingParty::find()->where(['id'=>***NEED TO PASS VALUE HERE***])->all(),'id','to_main'),
[
'prompt'=>'-Select To Main-',
]
);
//echo $form->field($modelBill, 'to_main')->textInput(['maxlength' => true]);
//$form->field($modelBill, 'to_main')->textInput(['maxlength' => true]);
echo $form->field($modelBill, 'bill_to')->textInput(['maxlength' => true,'readonly'=>true]);
echo $form->field($modelBill, 'billing_address')->textInput(['maxlength' => true,'readonly'=>true]);
echo '<div class="form-group">';
echo Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success']);
echo '</div>';
ActiveForm::end();
echo '</div>';
Modal::end();
This Modal is an input form that will pop out of the screen when the button is clicked.
The issue is that I need to pass the PHP variable inside the Grid view which is $getCode to the Modal. I need to pass the value in the dropdownlist in the Modal.
You can see the note 'NEED TO PASS VALUE HERE'
How do I solve this issue?