简单的html表单发布到两个不同的位置

时间:2013-03-26 13:08:07

标签: php html forms post

我希望能够将表单中的信息发布到两个位置。表单目前发布到一个位置。

<form name="input" action="display.php" method="post">
    search: <input type="text" name="item">
    title: <input type="text" name="title">
    Distance:
    <select type="text" name="distance">
        <option value="5">5 miles</option>
        <option value="10">10 miles</option>
        <option value="15">15 miles</option>
    </select>
</form>

我试过

<form name="input" action="display.php", "info.php" method="post">

希望它会发布到display.php和info.php,但没有运气。

2 个答案:

答案 0 :(得分:4)

为什么不为此使用ajax。它可以帮助您将2个请求发送到2个不同的页面。

$.ajax({
           type: "POST",
           url : "form.php",
           data: {'field1':field1,'field2':field2},
           success: function(msg){
                 // get response here  
               }
           });

$.ajax({
           type: "POST",
           url : "display.php",
           data: {'field1':field1,'field2':field2},
           success: function(msg){
                 // get response here  
               }
           });

答案 1 :(得分:0)

您最好的选择是使用史努比,因为它不会使用cURL。 (您可能有也可能没有,本课程不要求)。 该课程可在以下网址下载:http://sourceforge.net/projects/snoopy/ 您需要做的就是包含此类并将此代码用于多个帖子:

    $snoopy = new Snoopy;

     $submit_url = "url1.php";

     $submit_vars["foo"] = "bar";
     $submit_vars["key"] = "value";
     $submit_vars["input-name"] = "input-value";
     //making sense on what these are?

     $snoopy->submit($submit_url,$submit_vars);
     //additionaly you can print the results with:
     //print $snoopy->results;

     //then move to the next submit url
     //but, remember!  You must instantiate a new class

     $snoopy2 = new Snoopy;


 $submit_url = "url2.php";

 $submit_vars["foo"] = "bar";
 $submit_vars["key"] = "value";
 $submit_vars["input-name"] = "input-value";

 $snoopy2->submit($submit_url,$submit_vars);