Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在点击按钮时调用带有参数的php文件?_Php_Html - Fatal编程技术网

如何在点击按钮时调用带有参数的php文件?

如何在点击按钮时调用带有参数的php文件?,php,html,Php,Html,我在一个名为send_payment.php的文件中有以下代码。我想当表单被提交到某个地方时,它会向银行支付页面发送一些参数 <head> <script type="text/javascript"> function onLoad() { document.frmInput.submit(); } </script> </head> <body

我在一个名为send_payment.php的文件中有以下代码。我想当表单被提交到某个地方时,它会向银行支付页面发送一些参数

<head>
    <script type="text/javascript">
        function onLoad()
        {
            document.frmInput.submit();
        }   
    </script>
</head>

<body onLoad="onLoad();">
<form name="frmInput" id="frmInput" 
action="https://tmbepgw.tmbbank.com/TMBPayment/Payment.aspx" method="post">
    <input type="hidden" id=MERID name=MERID value="000001110801149">
    <input type="hidden" id=TERMINALID name=TERMINALID value="78000113">
    <input type="hidden" id=AMOUNT name=amount value="000000000000">
    <input type="hidden" id=BACKENDURL name=BackendUrl value="">
    <input type="hidden" id=RESPONSEURL name=ResponseUrl value="http://www.nibh.com/html">
    <input type="hidden" id=MERCHANTDATA name=merchantdata value="NIBH">
    <input type="hidden" id=INVOICENO name=INVOICENO value="090517153914">
    <input type="hidden" id=CURRENCYCODE name=CURRENCYCODE value="764">
    <input type="hidden" id=VERSION name=VERSION value="1.0">
</form>
</body>
</html>


函数onLoad()
{
document.frmInput.submit();
}   
我在我的网站上有一个表单提交的代码,点击一个按钮,其中包含一个href:

<a class="button" href="#">Make Payment</a>

在该代码中,我可以访问表单中的字段,如$AMOUNT等。。。对于send_payment.php

但是,我被卡住了。当用户单击submit时,我想进行与.php文件中相同的调用

  • 单击我的按钮时,如何调用与send_payment.php文件中相同的代码
  • 我只想在send_payment页面的“action”中发送相同的变量
  • 最好调用一个php文件来实现这一点吗?如果是的话,有关于如何将参数发送到php文件然后调用该URL的指南:

    “”method=“post”

  • 用我当时的变量?(例如:美元金额等)


    谢谢。

    仅使用PHP,要将帖子发送到两个文件,您需要使用CURL。 这样做:

    1) 在指向PHP文件(
    send\u payment.PHP
    )的
    form标记中设置
    action
    属性

    2) 在文件
    send_payment.php
    中,需要使用CURL将$\u POST变量发送到
    .aspx
    文件,如下所示:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://tmbepgw.tmbbank.com/TMBPayment/Payment.aspx");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $server_output = curl_exec($ch);
    curl_close($ch);
    
    if ( $server_output ){
        // true
    } else {
        //false
    }
    
    function send_payment_curl( $post, $to_url ){
         $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$to_url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $server_output = curl_exec($ch);
        curl_close($ch);
    
        if ( $server_output ){
            return true;
        } else {
            return false;
        }
    }
    
    这是使用CURL发送帖子的最简单方法。大多数主机服务器都启用了CURL。但是,如果确实启用了,请与主机联系。也许主机有一个在服务器中使用CURL的示例。但CURL并没有迷雾

    您可以将此代码放入函数中,如下所示:

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,"https://tmbepgw.tmbbank.com/TMBPayment/Payment.aspx");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST));
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $server_output = curl_exec($ch);
    curl_close($ch);
    
    if ( $server_output ){
        // true
    } else {
        //false
    }
    
    function send_payment_curl( $post, $to_url ){
         $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,$to_url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $server_output = curl_exec($ch);
        curl_close($ch);
    
        if ( $server_output ){
            return true;
        } else {
            return false;
        }
    }
    
    在文件
    send\u payment.php
    中,只需调用以下函数:

    $r = send_payment_curl( $_POST, "https://tmbepgw.tmbbank.com/TMBPayment/Payment.aspx" );
    
    if ( $r ){
        // it works!
    } else {
        // there's a problem with the CURL. Please check the code
    }
    

    我希望它能帮助你

    您应该查找
    $\u POST['amount']
    ..或
    $\u POST['amount']
    (数组中的键区分大小写)。我建议您将您的id和姓名用引号括起来。这两种方式都可以,但将所有参数值都用引号括起来更“正确”。首先,您如何提交表单?前面的按钮,href,提交按钮。我不知道我是否理解你的问题。您的表单将数据提交到“…Payment.aspx”,但您也希望将数据发送到另一个文件“…send_Payment.php”,对吗?换句话说,接收两个文件中的表单数据。如果它是正确的,我建议您使用ajax。你知道如何使用ajax吗?如果没有,我可以解释。问题太多;没有人接受。@Dr.somer,非常感谢,按钮上的代码现在可以调用了。但根据屏幕截图(),我正在努力处理$u POST变量。我想将相同的调用与send_payment.php中的原始调用中的所有相同变量进行匹配。如何将所有这些变量复制到$post变量中?curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($_POST));((我假设这是输入错误,应该是$post,因为这就是传递到此函数的内容)。变量如何:add@Dr.somer我只需要将所有这些变量发送到$post数组中<代码>'等。。etc.
    @wanwu当您向
    表单操作
    属性中指示的PHP文件发送帖子时,会自动创建
    $\u POST
    变量。此全局变量是一个数组,包含表单中的所有字段。示例:带有
    name=MERID
    value=000001110801149
    输入将在PHP文件中接收,如下所示:
    $\u POST['MERID']=000001110801149
    。所有字段都是一样的。字段属性名称将是
    $\u POST
    数组中的关联键。然后,如果在CURL中发送$\u POST变量,则发送的是原始调用。