繁体   English   中英

在提交之前将值传递给隐藏的输入值

[英]passing value to hidden input value before submit

我正在尝试运行一个将 Id 存储在隐藏输入标签中的表单,以便我可以使用 php 在下一页中检索它。 出于某种原因,我无法使用 php 文件检索值。 回显 orderId.value 和订单号工作正常。

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>

在编辑-form.php

<?php

$xyzabc = $_POST['orderId'];
echo $xyzabc;

?>

对于 $xyzabc 没有任何回应,如果没有 jQuery 有某种方法可以做到这一点,我更希望这样做,因为我对此很陌生,并且到目前为止还没有真正掌握一切如何协同工作。

您可以将值直接存储到隐藏的输入字段。

  <!--use the hidden input variable to save the order number clicked -->
        <input id="orderId" type="hidden" name="orderId" value="<?=$variable_name;?> />

这样当你提交表单时

 <?php

$xyzabc = $_POST['orderId'];
echo $xyzabc;

?>

将获取数据。 或者您可以在 url 中传递隐藏值。 例如

<a href="localhost:8000/edit-form.php?orderId="<?=$variable_name;?>

然后在你 form-edit.php

<?php

    $xyzabc = $_GET['orderId'];
    echo $xyzabc;

    ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM