Here is my basic form:
<form id="mgstaskvuephonecall" name="contactform" method="POST" >
<div class="mb-3">
<div class="input-group" id="fld1">
<input type="text" name="contact1" id="contact1" class="form-control tvc username" placeholder="Contact" aria-label="Username" alt="1">
<input type="text" name="phone1" id="phone1" class="form-control phone-number tvp" placeholder="Ex: +(000) 000-00-00" alt="1">
</div>
</div>
<div class="mb-3">
<div class="input-group" id="fld1">
<input type="text" name="contact2" id="contact2" class="form-control tvc username" placeholder="Contact" aria-label="Username" alt="2">
<input type="text" name="phone2" id="phone2" class="form-control phone-number tvp" placeholder="Ex: +(000) 000-00-00" alt="2">
</div>
</div>
<!-- ... a total of 5: contact1-contact5, phone1-phone5 -->
</form>
I am using AJAX to call php to pull data from the database, how then would I use the result to populate my form. I am stuck on handling the fields with same names just differenced by the sequential number on the end of it. Here's what I have so far, just stuck on how to manipulate results:
// fetch table data based on date
$("#form-date").on('change', function(){
var date = $(this).val();
$.ajax({
url: 'dynamic-pop-form.php',
method: 'POST',
data:{
"date":date
},
success: function(data){
var len = data.length;
...
}
}
});
});
dynamic-pop-form.php:
include('connection.php');
$formDate = $_POST['date'];
$formDate = strtotime($formDate);
$formDate = date('Y-m-d', $formDate);
$stmt = $conn->prepare("SELECT * FROM `my_table` WHERE `form_date` = ? LIMIT 5");
$stmt->bindParam(1,$formDate,PDO::PARAM_STR);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
echo json_encode( $result );