PHP表格打开新窗口

时间:2020-07-08 09:12:37

标签: javascript php html forms

我有一个正在构建的PHP网站,正在其中添加基本的产品订购单。我已经创建了表单元素,并且一旦用户选择了一个选项,我想打开一个新窗口(而不是选项卡),以该新窗口为焦点,并通过GET方法将变量传递给新打开的窗口。 / p>

当前,当我提交表单时,目标表单会根据js打开,但是url变量不会传递到新窗口。我的代码以某种方式同时打开了一个新标签页,并将GET URL转移到了新标签页,而不是新窗口中,从而导致具有正确URL的新标签页和没有正确URL的新窗口。

我很高兴有很多类似的问题,而且我花了数小时试图修复,但无济于事。

提前感谢您的时间

源表单HTML:

        <div class="prdContainer">
            <form method="GET" target="_blank" action="members_order.php" onsubmit="openMemberOrder()"  id='bcpot002' class="prdInput">
                <div class="prodDiv">
                    <button type="submit" id="catOrder" class="catOrder"><img id="prdImgThumb" name="bcpot002" src="../../../Images/Product_Catalogue/bcpot002/bcpot002_thumb.jpg" ></button>
                </div>
                <div class="formDiv">
                    <label for="cat_ID" value="">Product Name:</label>
                    <input type="text" id="catID" name="cat_ID" value="bcpot002" readonly><br>
                    <label for="cat_Desc">Product Description:</label>
                    <input type="text" id="catDesc" name="cat_Desc" value="Red_Pot" readonly><br>
                    <label for="cat_val">Per unit price $:</label>
                            <input type="number" id="catVal" name="cat_val" value="" readonly>
                    <input type="hidden" id="divHeight" name="DivHeight" value="1036" readonly>
                    <input type="hidden" id="divWidth" name="DivWidth" value="1543" readonly>
                </div>
            </form>
        </div>

源表单JS:

function openMemberOrder(url) {
    newwindow = window.open('members_order.php', 'members_order', 'width=1600px,height=2000px,toolbar=no,scrollbars=no,resizable=no');
    if (window.focus) {newwindow.focus()}

      if (!newwindow.closed) {newwindow.focus()}
    return false;
}

接收页面HTML:

<?php require_once('xxxxx/initialize.php');

        $catID = $_GET['cat_ID'];
        $catDesc = $_GET['cat_Desc'];
        $DivHeight = $_GET['DivHeight'];
        $DivWidth = $_GET['DivWidth'];

        echo "ID: " . $catID . "<b>";
        echo "Desc: " . $catDesc . "<b>";
        echo "Val: " . $catVal . "<b>";
        echo "H: " . $DivHeight . "<b>";
        echo "W: " . $DivWidth . "<b>";

?>

<body>
    <header id="memOrderHead" ></header>
    <div class="gridContainer" id="gridContainer" ></div>
        <article class="article" >
            <div class="orderDiv">
                <h3>Order Item</h3>
                <form class="orderInput">
                      <label for="cat_ID">Product name:</label>
                                <input type="text" id="catID" name="cat_ID" value="<?php echo $catID; ?>" readonly>
                                <label for="cat_Desc">Product description:</label>
                                <input type="text" id="catDesc" name="cat_Desc" value="<?php echo $catDesc; ?>" readonly>
                      <label for="cat_val">Per unit price $:</label>
                                <input type="number" id="catVal" name="cat_val" value="<?php echo $catVal; ?>" readonly>
                      <label for="cat_quant">Quantity ordered:</label>
                                <input type="number" id="orderQuant" name="cat_quant" min="0" placeholder="0">
                      <label for="cat_Total">Total Price $:</label>
                                <input type="number" id="orderTotal" name="cat_Total" min="0" placeholder="0" readonly>
                      <button type="button" class="orderButton" onclick="clearForm()">Clear</button>
                      <button type="button" class="orderButton" onclick="total()">Calculate Total</button>
                      <button type="button" class="orderButton" onclick="orderConfirm()" id="confirmReset">Submit</button>
                </form>
            </div>
        </article>

1 个答案:

答案 0 :(得分:0)

您可以使用HTML 5本地存储将数据从网页传递到新窗口。下面的帖子中提供了其他一些替代方法 JavaScript - How do I open a new page and pass JSON data to it?