Multiple Form Actions?

Submit two places one click

Here is something that might help.
Code:
<form name=myForm action= "mypage.php" method=post>
Name <input type="text" name="username">
Pass <input type="password" name="password">
<input type="submit" value="Send" name="split" 
                     onclick="return SplitButton();">

<script language="javascript">
<!--
function splitButton()
{
    document.myForm.action = "otherpage.php"    // 1st location
    document.myForm.submit();        // Submit 1st location

    document.myForm.action = "furtherpage.php"    // 2nd location
    document.myForm.submit();        // Submit 2nd location

    return true;
}
-->
</script>

Having a similar issue, but with a redirect. If the POST happens then the redirect gets skipped, but when it is switched the redirect interferes with the POST action.

Looking for something where both can happen at the same time not one after another. Any help appreciated.

Hope the snippet above helps with what you are trying to do.
 


Here's a more in depth jQuery version for anyone wondering:

Code:
<html>
    <head>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" language="javascript">
            //when the page is loaded lets start
            $(document).ready(function() {
                //bind a click function to the element with the id 'submit'
                $("#submit").click(function() {
                    //set the variable fname to the value of the element with the id 'fname'
                    var fname = $('#fname').val();
                    //set the variable lname to the value of the element with the id 'lname'
                    var lname = $('#lname').val();
                    //set the variable sizes to the value of the element with the id 'sizes'
                    var sizes = $('#sizes').val();
                    
                    $.post("http://url-1.tld/test.php",  //first url on where to post to
                        { first: fname, last: lname, size: sizes }, //post variables with be first, last, size.  
                                                                    //in php $_POST['first'], $_POST['last'], $_POST['size']
                        function(data){
                            //this is the callback function, you can use it to process any data that's returned
                            alert("Data Loaded: " + data);
                    });
                    $.post("http://url-2.tld/test.php",  //second url on where to post to
                        { first: fname, last: lname, size: sizes }, //post variables with be first, last, size
                        function(data){
                            //this is the callback function, you can use it to process any data that's returned
                            alert("Data Loaded: " + data);
                    });
                    //in this example the form is setup with an action to goto a success type page
                    //this command will cause the form with the id 'form' to submit just as if you pressed a normal submit button
                    //you could also just as easily use something like: window.location('address_goes_here');
                    $("#form").submit();                
                });
            });
        </script>
    </head>
<body>
    <form id="form" action="success.php" method="post">
        First Name: <input type="text" id="fname" /><br />
        Last Name: <input type="text" id="lname" /><br />
        <select style="padding:3px;position:relative;bottom:10px;" id="sizes">
            <option value="1">Women's Size 5 1/2 - 8 (S)</option>
            <option value="2">Women's Size 8 1/2 - 11 (M)</option>
            <option value="3">Women's Size 11 1/2 and Up (L)</option>
            <option value="4">Men's Size 7 1/2 - 10 (M)</option>
            <option value="5">Men's Size 10 1/2 - 13 (L)</option>
        </select>
        <input type="image" src="http://www.wickedfire.com/images/submit_btn.gif" id="submit" />
    </form>
    <body>
    </body>
</html>
 
  • Like
Reactions: Mike
PS. If you need to use GET then just change $.post to $.get.

The callback function is also optional, and can be removed.