0

您好,我正在使用步骤表格步骤 1、步骤 2 等

在这里我应用 jquery 并转到下一页,但我的问题是我没有在下一步请求中获取第一步的数据。这里只是单页面上的步骤,它们只是显示隐藏和阻止。我应该怎么做才能获取 php 请求所有步骤数据,直到最后一步完成

<form>
<div class="step1">
<input type="text" name="firstname">
</div>

<div class="step2">
<input type="text" name="lastname">
<div>

<input type="submit" name="sub">
<input type="button" name="next">
<input type="button" name"previous">

</form>

这里什么时候

4

2 回答 2

0

这取决于您的 php 实现,但您有两个选择:

1- 在每一步之后使用 ajax 将数据发送回服务器。2-为每个步骤使用单独的页面。

于 2013-11-18T05:38:03.927 回答
0

步骤 1中单击按钮时,

  1. 你插入到对应的表中,得到插入的id

  2. 将插入的 id 值保存在表单中的某个隐藏类型中。

步骤 2中单击按钮时,

  1. 您需要使用您在表单中保存的 id 更新插入的表行数据中的相应列及其值

继续相同的过程,直到完成所有步骤。

    <script>
        $(document).ready(function() {
           $("#next").click(function() {
             var currentStep = $('#currentStep').val(); // based on the step you need use some switch or conditional block to pass data and store it accordingly.
            // insertedId ==0 means you need to insert into table, if it not you need update the column in table

              var formdata = {insertedId:$("#insertedId").val(),currentStep:currentStep, first:$("#first").val()};

               $.ajax({
                 type: "POST",
                 url: "form.php",
                 dataType:'json',
                 data: formdata
                 })
                 .done(function( data ) {

                     var NextStep =parseInt(currentStep)+1;
                     $("#currentStep").val(NextStep);

                     $("#insertedId").val(data.insertedId);
                     $("#step"+currentStep).hide();
                     $("#step"+NextStep).show();

                 });
            });         
        });


    </script>

HTML:

        <div id="step1">Step 1:

            <input type="text" name="first" id="first" value="">

        </div>

         <div id="step2" style="display:none;">Step 2:

            <input type="text" name="last" id="last" value="">

        </div>

        <input type="hidden" name="insertedId" id="insertedId">
        <input type="hidden" name="currentStep" id="currentStep" value="1">
        <button id="next">Next</button>
于 2013-11-18T05:46:49.480 回答