提交时合并两种表单的值 [英] Merge values from two forms on submit

查看:147
本文介绍了提交时合并两种表单的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个html页面上有两种形式。使用jQuery,当提交第一个数据时,是否有可能将这两个表单中的数据放入POST数据中?解析方案

方法是在数据验证检查成功后,将form2的所有输入复制到form1中。这假定你没有进行AJAX提交。

  // form1的新的onsubmit函数
函数form1_onsubmit()
{
if(!EntryCheck())返回false; $('#form2:input')。not(':submit')。clone()。hide()。appendTo('#form1');

$

返回true;
}

如果您想要提交两次提交,可能是因为提交失败服务器,我们需要删除任何复制的输入,然后复制新的输入。

  //新的form1 $ onsubmit函数
函数form1_onsubmit()
{
$('#form1:input [isacopy]')。remove();

if(!EntryCheck())return false; $('#form2:input')。not(':submit')。clone()。hide()。attr('isacopy','y')。appendTo('#form1 );

返回true;
}


I have two forms on one html page. Using jQuery, is it possible to have the data from both forms go into the POST data when the first is submitted?

解决方案

One approach is to copy all of form2's inputs into form1 once the data validation check succeeds. This assumes you are not doing an AJAX submit.

// new onsubmit function for form1
function form1_onsubmit()
{
    if (!EntryCheck()) return false; 

    $('#form2 :input').not(':submit').clone().hide().appendTo('#form1');

    return true;
}

If you wanted to cater for hitting submit twice, possibly because of submit fail from the server, we would need to remove any copied inputs before copying in new ones.

// new onsubmit function for form1
function form1_onsubmit()
{
    $('#form1 :input[isacopy]').remove();

    if (!EntryCheck()) return false; 

    $('#form2 :input').not(':submit').clone().hide().attr('isacopy','y').appendTo('#form1');

    return true;
}

这篇关于提交时合并两种表单的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆