0

我正在使用 JQuery 选项卡提交动态表单字段,但问题是它只保留提交最后一个选项卡的值,因为它检查哪个选项卡是活动的,哪个不是活动的,因为它看到最后一个是活动的,所以它只发布该选项卡的值其他如 1、2、3 等。

这是我正在使用的 JQuery 代码:

$('#rootwizard').bootstrapWizard({onTabShow: function (tab, navigation, index) {
            var $total = navigation.find('li').length;
            var $current = index + 1;
            var $percent = ($current / $total) * 100;
            $('#rootwizard').find('.bar').css({width: $percent + '%'});
            // If it's the last tab then hide the last button and show the finish instead
            if ($current >= $total) {
                $('#rootwizard').find('.pager .next').hide();
                $('#rootwizard').find('.pager .finish').show();
                $('#rootwizard').find('.pager .finish').removeClass('disabled');
            } else {
                $('#rootwizard').find('.pager .next').show();
                $('#rootwizard').find('.pager .finish').hide();
            }
        }});
    $('#rootwizard .finish').click(function () {
        alert('Finished!, Starting over!');
        //$('#rootwizard').find("a[href*='tab1']").trigger('click');
        $("#mealForm").submit();
    });

mealForm是包含所有选项卡数据的表单 ID,但仅发布最后一个选项卡/活动选项卡值而不是所有选项卡。

这是使用 PHP 生成动态选项卡和动态表单的 HTML 代码,但它只提交活动选项卡数据而不是全部数据。

HTML:

 <div id="rootwizard">
                <div class="navbar">
                    <div class="navbar-inner">
                        <div class="container">
                            <ul>
                                <?php
                                for ($counter = 1; $counter <= $_POST['meal_numbers']; $counter++) {
                                    ?>
                                    <li><a href="#tab<?php echo $counter; ?>" data-toggle="tab">Meal <?php echo $counter; ?></a></li>
                                <?php } ?>
                            </ul>
                        </div>
                    </div>
                </div>
                <div id="bar" class="progress progress-striped active">
                    <div class="bar"></div>
                </div>
                <div class="tab-content">
                    <?php
                    for ($counter = 1; $counter <= $_POST['meal_numbers']; $counter++) {
                        ?>
                        <div class="tab-pane" id="tab<?php echo $counter; ?>">
                            <form action="process/adminProcess.php?page=addClientMealData" method="post" id="mealForm" class="form-horizontal">
                                <fieldset>
                                    <?php
                                    $mealData = 1;
                                    $QuerySet = $objadminViewFunctions->viewAllFoodCategoryData();
                                    while ($RecordSet = $QuerySet->fetch_object()) {
                                        ?>
                                        <div class="control-group">
                                            <label class="control-label" for="focusedInput"><?php echo $RecordSet->food_name . ' ' . $RecordSet->food_gram . ' (grams)'; ?></label>
                                            <div class="controls">
                                                <?php //print $objadminViewFunctions->viewFoodSourcesDropdownForAddPg($RecordSet->id); ?>
                                                <input class="input-xlarge focused" id="focusedInput" name="mealData[<?php echo $counter; ?>][<?php echo $mealData; ?>][macro_ratio]" type="text">
                                                <input type="hidden" name="mealData[<?php echo $counter; ?>][<?php echo $mealData; ?>][foodCategoryId]" value="<?php echo $RecordSet->id; ?>">
                                            </div>
                                        </div>
                                        <?php
                                        $mealData++;
                                    }
                                    ?>
                                </fieldset>
                                <ul class="pager wizard">
                                    <li class="previous first" style="display:none;"><a href="javascript:void(0);">First</a></li>
                                    <li class="previous"><a href="javascript:void(0);">Previous</a></li>
                                    <li class="next last" style="display:none;"><a href="javascript:void(0);">Last</a></li>
                                    <li class="next"><a href="javascript:void(0);">Next</a></li>
                                    <!--<li class="next finish" style="display:none;"><a href="javascript:;">Finish</a></li>-->
                                    <button type="submit" class="btn btn-primary next finish" style="display:none;">Submit</button>
                                </ul>
                            </form>
                        </div>
                    <?php } ?>

                </div>  
            </div>

以下是上述 HTML 表单数据的输出:

<div id="rootwizard">
  <div class="navbar">
    <div class="navbar-inner">
      <div class="container">
        <ul>
          <li><a href="#tab1" data-toggle="tab">Meal 1</a></li>
          <li><a href="#tab2" data-toggle="tab">Meal 2</a></li>
        </ul>
      </div>
    </div>
  </div>
  <div id="bar" class="progress progress-striped active">
    <div class="bar"></div>
  </div>
  <div class="tab-content">
    <div class="tab-pane" id="tab1">
      <form action="process/adminProcess.php?page=addClientMealData" method="post" id="mealForm" class="form-horizontal">
        <fieldset>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 60 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][1][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][1][foodCategoryId]" value="37">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 55 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][2][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][2][foodCategoryId]" value="2">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 50 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][3][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][3][foodCategoryId]" value="3">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 45 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][4][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][4][foodCategoryId]" value="4">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 40 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][5][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][5][foodCategoryId]" value="5">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 35 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][6][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][6][foodCategoryId]" value="6">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 30 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][7][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][7][foodCategoryId]" value="7">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 25 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][8][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][8][foodCategoryId]" value="8">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 20 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[1][9][macro_ratio]" type="text">
              <input type="hidden" name="mealData[1][9][foodCategoryId]" value="9">
            </div>
          </div>
        </fieldset>
        <ul class="pager wizard">
          <li class="previous first" style="display:none;"><a href="javascript:void(0);">First</a></li>
          <li class="previous"><a href="javascript:void(0);">Previous</a></li>
          <li class="next last" style="display:none;"><a href="javascript:void(0);">Last</a></li>
          <li class="next"><a href="javascript:void(0);">Next</a></li>
          <!--<li class="next finish" style="display:none;"><a href="javascript:;">Finish</a></li>-->
          <button type="submit" class="btn btn-primary next finish" style="display:none;">Submit</button>
        </ul>
      </form>
    </div>
    <div class="tab-pane" id="tab2">
      <form action="process/adminProcess.php?page=addClientMealData" method="post" id="mealForm" class="form-horizontal">
        <fieldset>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 60 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][1][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][1][foodCategoryId]" value="37">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 55 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][2][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][2][foodCategoryId]" value="2">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 50 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][3][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][3][foodCategoryId]" value="3">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 45 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][4][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][4][foodCategoryId]" value="4">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 40 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][5][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][5][foodCategoryId]" value="5">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 35 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][6][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][6][foodCategoryId]" value="6">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 30 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][7][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][7][foodCategoryId]" value="7">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 25 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][8][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][8][foodCategoryId]" value="8">
            </div>
          </div>
          <div class="control-group">
            <label class="control-label" for="focusedInput">Protein 20 (grams)</label>
            <div class="controls">
              <input class="input-xlarge focused" id="focusedInput" name="mealData[2][9][macro_ratio]" type="text">
              <input type="hidden" name="mealData[2][9][foodCategoryId]" value="9">
            </div>
          </div>
        </fieldset>
        <ul class="pager wizard">
          <li class="previous first" style="display:none;"><a href="javascript:void(0);">First</a></li>
          <li class="previous"><a href="javascript:void(0);">Previous</a></li>
          <li class="next last" style="display:none;"><a href="javascript:void(0);">Last</a></li>
          <li class="next"><a href="javascript:void(0);">Next</a></li>
          <!--<li class="next finish" style="display:none;"><a href="javascript:;">Finish</a></li>-->
          <button type="submit" class="btn btn-primary next finish" style="display:none;">Submit</button>
        </ul>
      </form>
    </div>
  </div>
</div>

按照上面的 HTML 截图:

选项卡 1

选项卡 1

选项卡 2

选项卡 2

4

1 回答 1

0

您将每个选项卡用作单独的表单。这就是为什么您只能提交一个标签的原因。仅使用一种在引导选项卡之前打开和之后关闭的表单

<form action="process/adminProcess.php?page=addClientMealData" method="post" id="mealForm" class="form-horizontal">
    <div class="tab-content">
      .....
    </div>
</form>
于 2015-08-23T23:58:50.977 回答