Web Form Actions

I have a webform that gathers information from a potential customer and then emails the information to a specific email address.  This all works fine.  My client would like the information to now be delivered to a lead gathering website service.  It has its own <form action...>

Is there a way to have two form actions on one page, for the same form?
LVL 7
rgranlundAsked:
Who is Participating?
 
Ray PaseurCommented:
HTML forms can only submit the data to one location; that is the URL given in the action= attribute of the form tag.  You might consider a couple of design ideas to get past this issue.  One idea might be to use an action script that both sends the email and reposts the data to another script.  Whatever script is identified in action= needs to be the script that does the server-side data validation.

This script does not work on my server because of security settings relative to fSockOpen() and HTTP protocol.  The admin requires fSockOpen() to use HTTPS and I do not have a security cert on this machine.  However it teaches a principle that might be what you want to try.

HTH, ~Ray
<?php // RAY_post_to_multiple_pages.php
error_reporting(E_ALL);
echo "<pre>\n";


// Q: HOW CAN I HAVE A FORM THAT POSTS TO MORE THAN ONE ACTION SCRIPT?
// A: USE A CANONICAL SCRIPT TO RE-POST THE DATA TO THE OTHER ACTION SCRIPTS.



// THE LIST OF URLS AND ACTION SCRIPTS - USE AS MANY AS NEEDED - DIFFERENT NAMES, ETC
$target["www.laprbass.com"] = 'RAY_bounce_post.php';
$target["www.laprbass.com"] = 'RAY_bounce_post.php';
// NOTE IN THIS EXAMPLE THERE IS ONLY ONE ADDITIONAL SCRIPT - ARRAY OVERWRITES



// THIS IS THE CANONICAL ACTION SCRIPT - IS ANYTHING POSTED?
if (!empty($_POST))
{
    // IF SO, REPACKAGE IT TO GO TO THE SUBSIDIARY SCRIPTS
    $repost = NULL;
    foreach ($_POST as $key => $val) // ASSEMBLE KEY=VAL PAIRS
    {
        $repost .= urlencode(stripslashes($key)) . '=' . urlencode(stripslashes($val)) . '&';
    }
    $repost = rtrim($repost, '&');   // REMOVE THE LAST AMPERSAND

    // ITERATE OVER THE TARGET SCRIPTS POSTING TO EACH ONE
    foreach ($target as $url => $page)
    {
        // SET UP POST DATA - NOTE VARS $url $page strlen($repost)
        $header = '';
        $header .= "POST /$page HTTP/1.0\r\n";
        $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
        $header .= "Content-Length: " . strlen($repost) . "\r\n\r\n";

        // OPEN THE SOCKET TO THE REMOTE PAGE
        $fp = fsockopen ($url, 80, $errno, $errstr, 30);

        // TEST FOR VERIFICATION
        if (!$fp) // HTTP ERROR
        {
            die("ERROR: fsockopen() FAILED \n ERRNO=$errno \n ERRSTR=$errstr \n");
        }

        // HTTP OPEN - WRITE HEADER AND POST REQUEST
        fputs ($fp, $header . $repost);

        // HTTP OPEN - READ RESPONSE, DISCARDING HEADERS TO THE VERY END (UNLESS YOU CARE)
        $replies = '';
        $headers = '';
        while (!feof($fp))
        {
            $replies  = fgets ($fp, 1024);
            echo PHP_EOL . "$replies"; // SHOW RETURNING HEADERS
            $headers .= $replies;
        }
        fclose ($fp);

        // SHOW THE BROWSER OUTPUT REPLIES, IF ANY, FROM THE REMOTE SCRIPTS
        echo PHP_EOL . "$url $page $replies";

    } // END OF ITERATOR OVER TARGET SCRIPTS
    echo PHP_EOL;

// END OF PHP - PUT UP THE HTML FORM
}
?>
<form method="post">
TYPE SOMETHING: <input name="thing_one" />
SOMETHING ELSE: <input name="thing_two" />
SEND RESPONSES: <input name="email" /> (YOUR EMAIL)
<input type="submit" value="MULTI-POST" />
</form>

Open in new window

0
 
Lukasz ChmielewskiCommented:
Yes. But it won't work :P Just add a Cc: field to your mail function sending a copy to another address
?
0
 
rgranlundAuthor Commented:
yeah but all of the validation is on one page that is not part of the new/additional action
0
 
Lukasz ChmielewskiCommented:
Why two actions then, when after the validation you could "do" both of the actions ?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.