[英]passing value to hidden input value before submit
I am trying to run a form that stores an Id in a hidden input tag so that I can retrieve it in the next page using php.我正在尝试运行一个将 Id 存储在隐藏输入标签中的表单,以便我可以使用 php 在下一页中检索它。 For some reason I can't retrieve the value using the php file.
出于某种原因,我无法使用 php 文件检索值。 Echoing orderId.value and order number are working fine.
回显 orderId.value 和订单号工作正常。
main_page.php main_page.php
<script>
function EditValues(orderNumber) {
var orderId = document.getElementById("orderId");
orderId.value = orderNumber;
document.forms["form1"].submit();
}
</script>
<body>
<form action="edit-form.php" id="form1">
<div class="container">
<!--use the hidden input variable to save the order number clicked -->
<input id="orderId" type="hidden" name="orderId"/>
<?php
require("config.php");
$con = new mysqli(DB_Host, DB_User, DB_Password, DB_Name);
if ($con->connect_error) {
die("Connection failed");
}
echo '<table id="tblOrders" name ="OrderTable" style="width: 100%">
<tr>
<th>Sno</th>
<th>Order Number</th>
</tr>';
$displayTableDataQuery = "SELECT id, orderNumber, customerName, deliveryDate FROM orderTable";
if ($tableData = $con-> query($displayTableDataQuery)) {
while($row = $tableData-> fetch_assoc()) {
$id = $row['id'];
$orderNumber = $row["orderNumber"];
echo '<tr >
<td>'.$id.'</td>
<td id = "orderNumber">'.$orderNumber.'</td>
<td><input type = "button" id ="editButton'.$id.'" value = "Edit" onclick = "EditValues('.$orderNumber.');"/> </td>
<td><input type = "button" id = "printInvoice'.$id.'" value="Print" onclick = "PrintInvoice('.$orderNumber.');" /> </td>
</tr>';
}
} else {
echo $con->error;
}
$tableData->free();
?>
</div>
</form>
</body>
In edit-form.php在编辑-form.php
<?php
$xyzabc = $_POST['orderId'];
echo $xyzabc;
?>
There is nothing echoed for $xyzabc I would prefer if there was some way to do this without jQuery as I'm kind of new to this and haven't really gotten a hang of how everything works together as of now.对于 $xyzabc 没有任何回应,如果没有 jQuery 有某种方法可以做到这一点,我更希望这样做,因为我对此很陌生,并且到目前为止还没有真正掌握一切如何协同工作。
You can store value directly to the hidden input field.您可以将值直接存储到隐藏的输入字段。
<!--use the hidden input variable to save the order number clicked -->
<input id="orderId" type="hidden" name="orderId" value="<?=$variable_name;?> />
So that when you submit the form这样当你提交表单时
<?php
$xyzabc = $_POST['orderId'];
echo $xyzabc;
?>
will fetch the data.将获取数据。 Or you can pass the hidden value in url.
或者您可以在 url 中传递隐藏值。 For example
例如
<a href="localhost:8000/edit-form.php?orderId="<?=$variable_name;?>
Then in you form-edit.php然后在你 form-edit.php
<?php
$xyzabc = $_GET['orderId'];
echo $xyzabc;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.