0

我正在设置一个潜在客户生成表单,该表单要求发送电子邮件,然后将其与一系列隐藏字段一起提交,以使该人订阅时事通讯。我想要做的是添加第二个表单,它将为不同的时事通讯提交一组不同的隐藏字段,但没有单独的提交按钮。

这个想法是,当用户提供他们的电子邮件时,只要他们不取消选中此复选框,他们的信息就会提交到两个表单。我怎么能这样做呢?示例 HTML:

        <form action="http://process.signupapp.com/" method="post" name="SimpleSignUp1">


         <input type="text" id="email" name="emailAddress"/>
         <input type="submit" name="submit" value="submit" id="signup">

                <input name="sourceId" type="hidden" value="code123" />
                <input name="listCode" type="hidden" value="GGGG" />              
                <input name="email_page" type="hidden" value="lettername" />
                <input name="email_subject" type="hidden" value="Welcome Message" />

        </form>

        <form action="http://process.signupapp.com/" method="post" name="SimpleSignUp">

                <input name="agree" type="checkbox" value="agree_terms" checked/>
                <label for="agree">Yes, I would also like to receive the FREE cool      newsletter</label>

<input type="submit" value="submit" />

<input name="sourceId" type="hidden" value="code2345" />
<input name="listCode" type="hidden" value="DDDD" />
<input name="email_page" type="hidden" value="anothername" />
<input name="email_subject" type="hidden" value="Welcome again" />

</form>
4

1 回答 1

0

您可以在第一个表单的提交过程中调用第二个表单的提交事件。(猜测html结构)

$('#form1').submit(function() {
    if(! $(this).find('#checkbox').is(':checked')) {
        $('#form2').submit(); //Will want to make this an ajax call
    }
}

$('#form2').submit(function() {
    $.ajax({
        data: $('#form2').serialize(), //Or specify yourself
        url: $('#form2').attr('action'),
        type: 'POST',
    });
    return false; //Don't want to redirect in the middle of both submissions
}
于 2013-04-09T21:20:48.677 回答