首页 > 解决方案 > 以模态显示表单的 POST 数据

问题描述

我有以下代码:

形式:

<form action="test.php" onsubmit="addForm(event)" id="testeForm" method="post">
    <input type="submit" name="payButton"  value="BUY">
    <input type="hidden" name="type" value="pgmType" />
    <input type="hidden" name="total" value="10.00" />
</form>

窗口模式(灯箱):

<div class="dark-pay" close="dark-pay" style="display:none">
    <div id="loadiFrame" data="test.php"></div>
</div>

Javascript:

function addForm(event){   
    document.querySelector(".dark-pay").style.display = "inline";
    $('#loadiFrame').html('<iframe style="border: 0;width: inherit;" src="' + $("#loadiFrame").attr("data") + '"></iframe>'); 
}

test.php 的内容

<?php

    $type = $_POST["type"];
    $total = $_POST["total"];
    echo "Type: ".$type." - Total: ".$total;

?>

我需要在灯箱中打开文件test.phpiframe,已经带有POST打印数据。

我已经尝试使用网站上的几个示例,但无法实现。就像现在一样,它会打开 ,modal但会将用户重定向到新选项卡,而不是在modal.

这是一个支付网关,客户单击 上的购买按钮form,然后灯箱(模态)打开表单数据,然后使用此数据重定向到支付方式,所有这些都在模态中而不离开页面。

在文件test.php中,我需要创建一个重定向,我不知道这是否也适用于模态。

关于如何做到这一点的任何想法?

标签: javascripthtmlajaxmodal-dialoglightbox

解决方案


推荐阅读