发送HTML表单到外部服务

发送HTML表单到外部服务

问题描述:

我有一个请求来确定是否有可能在不丢失网站上的当前表单处理的情况下将令人兴奋的HTML表单发送到外部服务。发送HTML表单到外部服务

基本思路是:

  1. 游客在填写表单
  2. 表单数据发送到做它自己的形式处理
  3. 形式继续执行它的网站本身对自己的POST数据的外部web应用(发送电子邮件给访问者等)

我正在寻找一些输入第2步。我被要求建立一个简单的仪表板,保存所有的表格数据与导出的乐趣ctionality,但他们想要保持当前网站上的所有表单处理。

我希望有人可以给我一些关于如何寻找关键字到谷歌或一些技术检查的输入。

在此先感谢

+0

基本上你想发送两个POST/GET请求到不同的目的地,同时用一个提交动作,是吗? –

+0

基本上是=') –

+2

AFAIK是可能的。阅读[this](http://stackoverflow.com/questions/1585307/how-to-form-post-to-multiple-locations)和[this](http://www.html-form-guide.com/网络表格/提交 - 成型 - 多scripts.html)。 –

也许下面的代码是有益

<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> 

发现here

+0

我想过的JavaScript/jQuery/AJAX来处理表单数据,但我宁愿不依靠客户端为此。 –

+1

所以你想通过PHP做到这一点。 [This](http://stackoverflow.com/questions/1217824/post-to-another-page-within-a-php-script)将完成这项工作! –

+0

我通过@Alan Machado发现了类似的东西 –

理念是读取所需要发布的数据,并在外部和本地网站第一然后在AJAX请求的帮助下发布它会更好(如下所示)。

或者有两种形式,一旦用户点击提交,以编程方式填充这两种形式和提交请求。

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

我不想依赖客户端,所以我使用了cURL解决方案 –