doucheng1063 2015-04-09 15:35 采纳率: 100%
浏览 36
已采纳

多个表单发布到1个文档中的多个PHP脚本

I'm trying to Post a form:

<form role="form" method="post">
    <select name="inputStore">
        <option value="1">1</option>
        <option value="2">2</option>
    </select>
    <button type="submit">Show items</button>
</form>

to a PHP script which generates another form in it. Now im trying to post the PHP form to another PHP script inside of the current document.

Example:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Example</title>
</head>

<body>

<form>First form posts to PHP</form>
<?php First PHP which generates another Form ?>
<form>Form which got generated from the first PHP post. This form should POST to the second PHP</form>
<?php Second PHP ?>
</body>

</html>

How would I get this working? The PHP scripts have to stay at their positions. Cant wrap those two inside one PHP Tag

  • 写回答

1条回答 默认 最新

  • douwu7563 2015-04-09 16:02
    关注

    Here is the thing you wanted to do

    Here i am just sending the value to another and just retuning the same to the parent file.

    index.php (that is in the front)

       <script src="http://code.jquery.com/jquery-1.7.2.js"></script>
    <form role="form" method="post">
        <select name="inputStore" onchange="getval(this);">
            <option value="1">1</option>
            <option value="2">2</option>
        </select>
    </form>
    <div id='result'>
    </div>
    
    <script type="text/javascript">
        function getval(sel) {
        var datas =sel.value;
        console.log(datas);
           $.ajax({
            type: "POST",
            url : "response.php",
             data: { 
            'selected': datas, 
        },
            success : function(data)
            {
            console.log(data);
            $("#result").html(data);
            }
        },"json");
    
        }
    </script>
    

    response.php That will process your request

    <?php
    $value = $_POST['selected'];
    echo 'This is sent from server '.$value.' - End';
    ?>
    

    Update :

    (As the questioner wants to see output for 2 inputs at same time )

    Here is the Front File :

    <script src="http://code.jquery.com/jquery-1.7.2.js"></script>
    <form role="form" method="post">
        <select name="inputStore" id="inputStore" >
            <option value="stud">Male Hottie</option>
            <option value="babe">Female Hottie</option>
        </select>
        <select name="inputStoretwo" id="inputStoretwo">
            <option value="20037336">Artizans</option>
                                                            <option value="20080134">Bwabies!</option>
                                                            <option value="20097365">Crave Mart</option>
                                                            <option value="20099998">David &amp; Goliath</option>
                                                            <option value="20098166">Domo</option>
                                                            <option value="20101926">Emily the Strange</option>
                                                            <option value="20098167">Garfield</option>
                                                            <option value="26">Jetsetter</option>
                                                            <option value="3">Like Dat</option>
                                                            <option value="21">Paris Hilton</option>
                                                            <option value="19">Rocawear</option>
                                                            <option value="10">ShoeBuy</option>
                                                            <option value="20100198">Skelanimals</option>
                                                            <option value="20096121">SW&amp;TH</option>
                                                            <option value="1">The Castle</option>
                                                            <option value="4">The Lair</option>
                                                            <option value="923">The Mix</option>
                                                            <option value="20098121">The Powerpuff Girls</option>
                                                            <option value="5">The Surf Shop</option>
                                                            <option value="20076231">Tie The Knot</option>
                                                            <option value="20099224">Tokidoki</option>
                                                            <option value="2">University Club</option>
                                                            <option value="6">Z Avenue</option>
                                                            <option value="20099506">Z's Greetings</option>
                                                            <option value="20">Snoop Dog</option>
        </select>
    </form>
    <button>Pass the value</button>
    
    <div id='result'>
    </div>
    
    <script type="text/javascript">
    
    $("button").click(function(){
       var first = $("#inputStore option:selected").text();
       var second = $("#inputStoretwo option:selected").text();
        $.ajax({
            type: "POST",
            url : "response.php",
             data: { 
            'firstvalue': first, 
            'secondvalue': second, 
        },
            success : function(data)
            {
            console.log(data);
            $("#result").html(data);
            }
        },"json");
    });
    </script>
    

    and here is the response file :

    <?php
    $first = $_POST['firstvalue'];
    $second = $_POST['secondvalue'];
    echo 'This is first value : '.$first.'<br> and this is the second value : '.$second;
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统