简体   繁体   English

以两种形式发布数据,第一种形式在填写第二种形式之前不会发送任何数据

[英]Post data in two forms, The first form doesn't send any data until the second one is filled out

Basically I have two forms. 基本上我有两种形式。 I want to have a user upon registration fill out the first lot of information. 我想让用户在注册时填写第一批信息。 Press next (submit), then fill out the second lot of information. 按下一步(提交),然后填写第二批信息。 Once they press register, submit both sets of POST information. 他们按下注册后,提交两组POST信息。

What I have is this - two sections with two different forms (there's a reason why these are split into two forms - part of the look of the site): 我所拥有的是-具有两种不同形式的两个部分(将其分为两种形式的原因-该网站外观的一部分):

<section class="first">
    <header>
        <h1>Signup 1/2</h1>
    </header>
      <form id="firstForm">
          <label>First Name</label>
          <input type="text" class="input-text" value="" name="firstName" required />
          <label>Surname</label>
          <input type="text" class="input-text" value="" name="Surname" required />
          <label>Username</label>
          <input type="text" class="input-text" value="" name="Username" required />
        <input type="submit" name="firstSubmit" value="next"/>
      </form>
</section>
<section class="second">
    <header>
        <h1>Signup 2/2</h1>
    </header>
      <form name="secondForm" class="clearfix">
          <label>Your Email</label>
          <input type="email" class="input-text" value="" name="email" required />
          <label>Password</label>
          <input type="text" class="input-text" value="" name="password" required />
        <input type="submit" name="secondSubmit" value="Register" />
      </form>
</section>

So the second section is hidden until the user clicks the next button (submit). 因此,第二部分是隐藏的,直到用户单击下一个按钮(提交)。 I have javascript stopping it from submitting, and hiding the first section, and making the second one appear: 我有javascript阻止它提交,并隐藏了第一部分,并使第二部分出现:

<script type="text/javascript">
$("#firstForm").bind("submit", nextForm);
function nextForm() {
    $('.first').css("display", "none");
    $('.second').css("display", "block");
    return false;
}

This works. 这可行。 My issue is then getting the secondForm to submit, but POST both the first and second's information, as if with the one submit button, I was submitting both. 然后,我的问题是让secondForm提交,但是同时发布第一和第二个信息,就像使用一个提交按钮一样,我同时提交了这两个信息。 Is this possible? 这可能吗? And if so, how? 如果是这样,怎么办?

To use a GET method I'd go: 要使用GET方法,我会去:

$("#secondForm").bind("submit", submitForm);
function submitForm() {
    document.getElementById("firstForm").submit();  
    document.getElementById("secondForm").submit();         
}

But I don't want to do that, as GET = a bad idea for sensitive info. 但我不想这样做,因为GET =敏感信息的好主意。

I would use one form, but wrap the two sets of inputs in divs. 我将使用一种形式,但将两组输入包装在div中。 Just hide the first div and show the second on the first button click (which you wouldn't keep as a submit button), then submit the entire form on the second button click. 只需隐藏第一个div,然后在第一次单击按钮时显示第二个div(您将不会保留它作为提交按钮),然后在第二次单击按钮时提交整个表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM