HTML表单的多个操作

时间:2012-04-30 05:08:18

标签: php html

我正在尝试制作和HTML表单发布到2个不同的PHP脚本。一个在我的服务器上,另一个在另一个上。基本上我试图让它成为action =“script1.php”action =“script2.php”我不确定我是否可以使用我的php脚本将$ _POST数组转发到另一个php脚本。如果你能提供帮助,请告诉我

3 个答案:

答案 0 :(得分:3)

您可以使用cURL将数据发送到Script2.php,来自script1.php。

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://whatever/script2.php');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($_POST);
curl_exec($ch);
curl_close($ch);

未经测试,但类似的东西应该适合你。另见:http://davidwalsh.name/execute-http-post-php-curl

http://php.net/manual/en/function.http-build-query.php

答案 1 :(得分:1)

在您的php服务器上使用curl将信息发布到另一台服务器。

答案 2 :(得分:0)

您可以使用javascript执行此操作。你可以让这个表单有一个特殊的类“DoubleAction”,然后在javascript中,你可以检查并将表单发布到这两个动作,如下面的javascript示例:

if ( obj.hasClass('DoubleAction') ) {
        obj.submit(function() {


            var params = $(this).serialize(); 

            $.post( this.getAttribute("action"), params, clientData.ajaxLinksClient.complete );

            action2 = $(this).attr('action2');
            if ( typeof(action2) != 'undefined' && action2 != null && action2 != '' ) {
                $.post( action2, params );
            }
        });
    }