我想将PHP变量发送给模式变量,但还需要获取一个php变量

时间:2019-03-01 17:28:11

标签: php ajax variables

我有2种以上的表格

<body>
<form id="form1">
    <input type="hidden" name="var1" value="value1">
    <input type="submit" name="button1" data-toggle='modal' data-target='#myModal'>
</form>
<form id="form2">
    <input type="hidden" name="var2" value="value2">
    <input type="submit" name="button2" data-toggle='modal' data-target='#myModal'>
</form>
<form id="form3">
    <input type="hidden" name="var3" value="value3">
    <input type="submit" name="button3" data-toggle='modal' data-target='#myModal'>
</form>
</body>

然后我尝试将1个值发送到相同的模态并尝试使用变量

我需要知道哪个按钮发送哪个变量

<div class="modal fade" id="userEdit">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
            <?php
            // I need to know which button send which variable
            $var = $_POST["var1"];
            echo ($var);
            ?>  
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="submit" class="btn btn-primary"  name="button1">Submit</button>
            </form>
            </div>
        </div>
    </div>
</div>

我该怎么做。或您对我的建议有何建议? 我尝试使用Ajax多次,但未成功。你能给我一个可行的例子吗? 谢谢

1 个答案:

答案 0 :(得分:0)

以您的模态尝试:

for($i=1;$i<=10;$i++) {
    $var = ''; 
    if(isset($_POST["var".$i])) {
        echo 'Horray, its var number '.$i; 
        $var = $_POST["var".$i];
        break;
    }
    echo ($var);
}