0

I've got a request to figure out if it's possible to send excisting HTML forms to an external service without losing the current form handling on the website.

Basically the idea is:

  1. Visitor fills in form
  2. Form data is send to external webapplication which does it's own form handling
  3. Form continues to execute it's own POST data on the website itself (sending emails to visitor etc)

I'm looking for some input on step 2. I'm requested to build a simple dashboard that saves all the form data with an export functionality but they want to keep all the current form handling on the website as well.

I'm hoping someone can give me some input on what to look for as in keywords to google or some techniques to check out.

Thanks in advance

Jebble
  • 266
  • 1
  • 11
  • Basically you want to send two POST/GET requests to different destinations, at the same time, with a single submitting action, is that it? – al'ein Oct 06 '15 at 13:07
  • 2
    AFAIK it is possible. Read [this](http://stackoverflow.com/questions/1585307/how-to-form-post-to-multiple-locations) and [this](http://www.html-form-guide.com/web-form/submit-form-multiple-scripts.html). – al'ein Oct 06 '15 at 13:14
  • I've read the posts and will look into cURL for handling the form data. Thanks for pushing me into a direction! – Jebble Oct 06 '15 at 13:19

2 Answers2

0

Maybe the following code is helpfull

<html>
<head>
<script language="Javascript">
<!--
function OnButton1()
{
    document.Form1.action = "response1.php"
    // document.Form1.target = "_blank";    // Open in a new window

    document.Form1.submit();             // Submit the page

    return true;
}

function OnButton2()
{
    document.Form1.action = "" 

    document.Form1.submit();             // Submit the page

    return true;
}
-->
</script>
<noscript>You need Javascript enabled for this to work</noscript>
</head>
<body>
<!-- create the form -->
<form name="Form1" method="post">

<!-- Add the data entry bits -->
Your Name <input type="text" name="name" size="10" /><br />

<!-- Add some buttons -->
<INPUT type="button" value="Button1" name=name onclick="OnButton1(); OnButton2();">
<!-- close the form -->
</form>
</body>
</html>

Found it here

Alekos Dordas
  • 802
  • 7
  • 20
  • I've thought of javascript / jQuery / AJAX to handle the form data, but I rather not rely on the client-side for this. – Jebble Oct 06 '15 at 13:20
  • 1
    So you want to do this through php. [This](http://stackoverflow.com/questions/1217824/post-to-another-page-within-a-php-script) will do the job! – Alekos Dordas Oct 06 '15 at 13:24
  • I found something similar indeed through @Alan Machado – Jebble Oct 06 '15 at 13:28
0

Idea is to read the data that is needed to post and to the external and local site first then post it with help of AJAX request that would be much better (as shown below).

Or have two forms once user click submit populate both forms and the submit request programatically.

<div>
    <form action="" id="helloForm">
        Enter Text: <input type="text" id="txt" />
        <input type="button" value="submit" id="submitButton"/>
    </form>
</div>


$("#submitButton").click(function(e){

   //extract data
    var data = {
        text: $("#txt").val()
    };
    alert(JSON.stringify(data));

    //make external request one
    $.post( "externalpage.php", data);

    //make external request two
    $.post( "ownserverpage.php", data);
});
Anil Namde
  • 6,452
  • 11
  • 63
  • 100