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();
    });

食事フォームは、すべてのタブのデータを含むフォーム 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

各タブを個別のフォームとして使用しています。そのため、提出できるタブは 1 つだけです。ブートストラップ タブの前に開き、タブの後に閉じるフォームを 1 つだけ使用する

<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 に答える