2

这是我要回显提交的数据的表单,我曾经使用$_POST['field_name']; 回显数据; 但是这个表格有一个可重复的字段,我找不到解决方案,请帮助我,我是一个学习者。提前致谢。

插件使用https://github.com/DubFriend/jquery.repeater

PHP 代码

<?php
  if( 'POST' == $_SERVER['REQUEST_METHOD'] && !empty( $_POST['action'] ) &&  $_POST['action'] == "fields_details") {


//i couldn't figure out how to store the input fields data

$car_make= $_POST['car[0][make]'] 
$car_model= $_POST['car[0][model]'] 
$car_features= $_POST['car[0][features]'] 

echo $car_make;
echo $car_model;
echo $car_features;

}?>

HTML 代码

 <form method="POST" class="form-horizontal well" role="form">
      <fieldset>
        <legend>Cars</legend>
        <div class="repeater-default">
          <div data-repeater-list="car">
            <div data-repeater-item="">
              <div class="form-group">
                <label class="col-sm-1 control-label">Make</label>
                <div class="col-sm-2">
                  <select name="car[0][make]" class="form-control">
                    <option value="volkswagon" selected="">Volkswagon</option>
                    <option value="honda">Honda</option>
                    <option value="ford">Ford</option>
                  </select>
                </div>

                <label class="col-sm-1 control-label">Model</label>
                <div class="col-sm-2">
                  <input type="text" name="car[0][model]" value="Beetle" class="form-control">
                </div>

                <div class="col-sm-4">
                  <label class="checkbox-inline">
                    <input type="checkbox" name="car[0][features][]" value="ac">
                    Air Conditioning
                  </label>

                  <label class="checkbox-inline">
                    <input type="checkbox" name="car[0][features][]" value="abs">
                    Anti-Lock Brakes
                  </label>
                </div>

                <div class="col-sm-2">
                  <span data-repeater-delete="" class="btn btn-danger btn-sm">
                    <span class="glyphicon glyphicon-remove"></span> Delete
                  </span>
                </div>
              </div>
            </div>


          <div data-repeater-item="" style="">
              <div class="form-group">
                <label class="col-sm-1 control-label">Make</label>
                <div class="col-sm-2">
                  <select name="car[1][make]" class="form-control">
                    <option value="volkswagon" selected="">Volkswagon</option>
                    <option value="honda">Honda</option>
                    <option value="ford">Ford</option>
                  </select>
                </div>

                <label class="col-sm-1 control-label">Model</label>
                <div class="col-sm-2">
                  <input type="text" name="car[1][model]" value="Beetle" class="form-control">
                </div>

                <div class="col-sm-4">
                  <label class="checkbox-inline">
                    <input type="checkbox" name="car[1][features][]" value="ac">
                    Air Conditioning
                  </label>

                  <label class="checkbox-inline">
                    <input type="checkbox" name="car[1][features][]" value="abs">
                    Anti-Lock Brakes
                  </label>
                </div>

                <div class="col-sm-2">
                  <span data-repeater-delete="" class="btn btn-danger btn-sm">
                    <span class="glyphicon glyphicon-remove"></span> Delete
                  </span>
                </div>
              </div>
            </div></div>
          <div class="form-group">
            <div class="col-sm-offset-1 col-sm-11">
              <span data-repeater-create="" class="btn btn-info btn-md">
                <span class="glyphicon glyphicon-plus"></span> Add
              </span>
            </div>
          </div>

          <hr>

        </div>
        <div class="form-group">
          <div class="col-sm-offset-1 col-sm-11">
    <input type="hidden" name="action" value="fields_details" />

            <input type="submit" value="Submit" class="btn btn-primary btn-lg">
          </div>
        </div>
      </fieldset>
    </form>
4

0 回答 0