JavaScript配列のPHP配列からget perticularフィールドを変換するには?
検索ボタンをクリックした後、携帯電話番号とヒットデータベースを取得します。結果がnullでない場合は、このfname、lname ....すべてのフィールドは、更新フォームのような塗りつぶしフォームで開きますが、結果が得られない場合、空白になります.... 検索ボタンに1つの関数を書き込みます携帯電話番号や追加出荷の..私の出荷コントローラにでajax.andを使用してメソッドを作成一つの方法は、私は携帯電話番号を取得し、結果チェック条件ごとに作成
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.php ) 、出荷フォームでは、このFNAME、lanameすべての詳細は、出荷番号を顧客テーブルに保存したアドレスを、ボタンを作成
<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]) ?>
ありがとうございました...私の作成部分は、更新部分のみがリームされていますので、私のif(count($ modelArray)> 0){...}条件はajaxレスポンスで正しく動作しますが、テキストフィールドでこの応答を設定することができません...私はajax関数を更新します –
私はあなたのコメントを理解していない...私の答えはあなたが必要かどうかですか? – scaisEdge
はい、私のために完全に答えの助けをしています –