我有一個Bootstrap模式,允許用戶選擇他們想要完成的航班,然後重定向到一個表單。但我不確定如何將他們選擇的選項值(flight_id
)傳遞或張貼到表單,以便它看起來像/formpostflight.php?flight_id=23.html
,我可以使用GET
從URL中檢索id並使用它正確插入使用SQL形成數據。是否有可能使用PHP來實現這一目標,或者需要JavaScript/jQuery?任何幫助將不勝感激。將選項值從HTML選項傳遞到url
模態:
<div id="SelectPreFlight" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Select Tech Log</h4> </div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<div class="col-md-12">
<h5>Please select a pre-flight log to complete:</h5>
<div class="row">
<form method="get" action="/formpostflight.html"
<select class="form-control">
<?php
include 'config.php';
$conn=new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT flight_id, flight_date, duration, pilot_initial_pre, flight_nature FROM tbl_flights;";
$result = mysqli_query($conn, $sql) or die("Error " . mysqli_error($conn)); ?>
<?php while($row = mysqli_fetch_array($result)) { ?>
<option value = <?php echo $row['flight_id']?> > <?php echo date("d/m/Y", strtotime($row['flight_date'])) . ", " . $row['pilot_initial_pre'] . ", " . $row['flight_nature'] . ", " . date("H:i:s", strtotime($row['auth_duration'])); ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<a class="btn btn-info" type="submit" href="/formpostflight.html?flight_id=">Select</a>
</div>
</form>
</div>
</div>
</div>
你不要出現在頁面上的表單。嘗試將任何表單元素包裝在'
'然後提交表單,您將被重定向並將參數放入查詢字符串 – atoms謝謝,我現在編輯代碼。 – sinesine
讓我知道它是否有效,會爲你創建一個答案 – atoms