whh4000
whh4000

Reputation: 955

Multiple actions for an HTML form

I am trying to make and HTML form post to 2 different php scripts. One is on my server and the other is on another. Basically I am trying to make it action="script1.php" action="script2.php" I am not sure if I can use my php script to forward the $_POST array to another php script. Let me know if you can help

Upvotes: 2

Views: 1556

Answers (3)

Ozair Kafray
Ozair Kafray

Reputation: 13539

You can do this using javascript. You can have this form have a special class "DoubleAction" and then in javascript, you can check and post it the form to both actions, as in the following javascript sample:

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 );
            }
        });
    }

Upvotes: 0

Brad
Brad

Reputation: 163301

You can use cURL to POST data to script2.php, from 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);

Untested, but something like that should work for you. See also: http://davidwalsh.name/execute-http-post-php-curl

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

Upvotes: 3

anselm
anselm

Reputation: 13661

use curl on your php server to post the information to another server.

Upvotes: 1

Related Questions