Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 要使html表单运行两个操作_Php_Html_Forms_Form Submit_Input Type File - Fatal编程技术网

Php 要使html表单运行两个操作

Php 要使html表单运行两个操作,php,html,forms,form-submit,input-type-file,Php,Html,Forms,Form Submit,Input Type File,是否可以使用一个提交按钮提交两个表单 就像用户在表单上单击submit一样,该表单运行test.php和form.php,并且变量保持不变 如果不是,那么当用户在一个表单上单击submit时,它是否可能只运行test.php,然后test.php运行form.php,变量仍然保持不变。表单只能有一个操作,如果您想将数据传递到另一个页面,那么您可以通过调用ajax函数来实现这一点。我认为在普通表单提交中不可能做到这一点,但您可以尝试根据需要在两个表单上使用ajax请求。(这只是一个例子,没有经过测

是否可以使用一个提交按钮提交两个表单

就像用户在表单上单击submit一样,该表单运行
test.php
form.php
,并且变量保持不变


如果不是,那么当用户在一个表单上单击submit时,它是否可能只运行
test.php
,然后
test.php
运行
form.php
,变量仍然保持不变。

表单只能有一个操作,如果您想将数据传递到另一个页面,那么您可以通过调用ajax函数来实现这一点。

我认为在普通表单提交中不可能做到这一点,但您可以尝试根据需要在两个表单上使用ajax请求。(这只是一个例子,没有经过测试,只是一个指南或想法。)


表格#1
用户名:
密码:

表格#2 名字: 姓氏: 提交 $(文档).ready(函数(){ $(“#提交”)。在('单击',函数()上{ $.ajax({ url:$('#form_1').attr('action'), 数据:$('#form_1')。序列化(), 键入:“POST”、//或其他任何内容 数据类型:“JSON”、//或任何xml脚本html 成功:功能(响应){ } }); $.ajax({ url:$('#form_2').attr('action'), 数据:$('#form_2')。序列化(), 键入:“POST”、//或其他任何内容 数据类型:“JSON”、//或任何xml脚本html 成功:功能(响应){ } }); }); });
<!-- forms -->
<fieldset><legend>Form #1</legend>
    <form id="form_1" action="test.php">
        <label>Username: <input type="text" name="username" /></label>
        <label>Password: <input type="text" name="password" /></label>
    </form>
</fieldset>
<br/>
<fieldset><legend>Form #2</legend>
    <form id="form_2" action="form.php">
        <label>Firstname: <input type="text" name="fname" /></label>
        <label>Lastname: <input type="text" name="lname" /></label>
    </form>
</fieldset>

<button id="submit" type="button">Submit</button>
<!-- the forms is just an example -->
<!-- it would be weird to separate such fields in to different forms -->

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

    $('#submit').on('click', function(){

        $.ajax({
            url: $('#form_1').attr('action'),
            data: $('#form_1').serialize(),
            type: 'POST', // or whatever get
            dataType: 'JSON', // or whatever xml script html
            success: function(response) {

            }
        });

        $.ajax({
            url: $('#form_2').attr('action'),
            data: $('#form_2').serialize(),
            type: 'POST', // or whatever get
            dataType: 'JSON', // or whatever xml script html
            success: function(response) {

            }
        });
    });

});
</script>