how to echo data of jquery repeater field

2.1k views Asked by At

This is the form I want to echo the data submitted , I used to echo data using $_POST['field_name']; but this form has a repeatable field and I couldn't find the solution , please help me I am a learner. thanks in advance.

plugin used https://github.com/DubFriend/jquery.repeater

PHP Code

<?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 Code

 <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>
0

There are 0 answers