After click on search button get the mobile number and hit database. if result not null then this fname,lname....all field open with fill form like update form but if result not get it will be open empty.... For that I am write one function on search button this button get mobile number and call one method which in my shipment controller create method using ajax.and in create i get a mobile number and as per result check condition..
public function actionCreate()
{
if(isset($_POST['mobilenumber'])) {
//$modelArray = Customers::find()->where(['cust_mobile' => $_POST['mobilenumber']])->one();
$connection = \Yii::$app->getDb();
$command = $connection->createCommand(
"SELECT * ".
"FROM customers AS C ".
"WHERE C.cust_mobile= " .$_POST['mobilenumber']
// "AND C.cust_mobile=" .$_POST['mobilenumber2']
);
$modelArray = $command->queryAll();
if(count($modelArray) > 0) {
print_r(json_encode($modelArray));
/*Here I wanna set data which is comming from response i.e in object($modelArray)
on same form i.e is like a update form i.e here update logic i want to apply*/
} else {
/*Here new record is create if enter mobile number is not exist*/
}
} else {
/*open form if mobile number not set*/
}
}
Form of add Shipment(shipment/_form.php) And In shipment form create button this fname,laname,address all detail save into customer table with shipment id
<script type="text/javascript">
function searchResult() {
var mobilenumber = document.getElementById('customers-cust_mobile').value;
$.ajax({
type: "POST",
data: {
mobilenumber: mobilenumber,
},
dataType: "json",
url: "index.php?r=shipment/create",
success: function(data){
$('#customers-cust_fname').val(data[0].cust_fname);
$('#customers-cust_mname').val(data[0].cust_mname);
$('#customers-cust_lname').val(data[0].cust_lname);
$('#customers-cust_email').val(data[0].cust_email);
$('#customers-cust_street').val(data[0].cust_street);
$('#customers-cust_address').val(data[0].cust_address);
}
});
}
</script>
<?= $form->field($modelCustomersSender, 'cust_mobile')->textInput(['maxlength' => true]) ?>
<?= $form->field($modelCustomersSender, 'cust_fname')->textInput(['maxlength' => true]) ?>
<?= $form->field($modelCustomersSender, 'cust_mname')->textInput(['maxlength' => true]) ?>
<?= $form->field($modelCustomersSender, 'cust_lname')->textInput(['maxlength' => true]) ?>