Php Form不捕获动态字段的值

时间:2017-07-15 09:53:24

标签: php jquery

我有一个用于订购鸡蛋的表单。在此我有一个动态创建表单组的按钮,用户可以在其中输入更多订单。这非常有效。 但是,我试图从动态生成的表单组中收集和显示信息(作为在插入到dB之前的开发期间的测试),但这不起作用。仅显示原始表单(非动态)中的一个信息。 任何协助解决这个问题将不胜感激。 这是我的php和jquery脚本。第一个PHP; 注意:请注意我还没有在这里清理我的脚本。肯定会这样做。

<?php
    require("includes/conn.php");
    $message = '';
    if (isset($_POST['order_submit'])){
        $type = $_POST['type'];
        $quant = $_POST['quant'];
        $client_name = $_POST['client_name'];
        $client_add= $_POST['client_add'];
        $mobile = $_POST['mobile'];
        $phone = $_POST['phone'];

        foreach($type AS $key=>$value){//echo out on the screen the entered values in the dynamic fields only returns the value entered into one field 
            echo $value;
        }
    }
?>

<form class="form-horizontal" method="post" action="" id="order_eggs">
   <div class="orders_details">
     <div class="form-group">
        <label for="type" class="col-md-2 control-label">Type</label>
        <div class="col-md-6">
            <select name="type[]" class="form-control type">
               <option value="">-- Select Type of Eggs --</option>
               <option value="wsmall">White Small (N550 per crate)</option>
               <option value="wmedium">White Medium (N620 per crate)</option>
               <option value="wjumbo">White Jumbo (N750 per crate)</option>
               <option value="bsmall">Brown Small (N530 per crate)</option>
               <option value="bmedium">Brown Medium (N600 per crate)</option>
               <option value="bjumbo">Brown Jumbo (N700 per crate)</option>
           </select>
        </div>
    </div>
    <div class="form-group">
       <label for="quant" class="col-md-2 control-label">Quantity(Crates)</label>
        <div class="col-md-6">
           <input type="text" class="form-control quant" name="quant[]" placeholder="Quantity of eggs">
        </div>
    </div>
   </div>
   </div>
   <div class="col-md-offset-4">
      <button type="button" class="btn btn-success" id="more_orders_btn">Add More Orders + </button>
    </div>                  
    <h4 class="text-center" id="form_subhead">Name, Address and Mobile number fields are compulsory</h4>
    <div class="form-group">
       <label for="client_name" class="col-md-2 control-label">Name</label>
       <div class="col-md-8">
           <input type="text" class="form-control client_name" name="client_name" placeholder="Full names of client">
       </div>
     </div>
    <div class="form-group">
        <label for="client_add" class="col-md-2 control-label">Address</label>
        <div class="col-md-8">
            <textarea class="form-control" name="client_add" placeholder="Full Address" rows="2"></textarea>
        </div>
    </div>
    <div class="form-group">
        <label for="mobile" class="col-md-2 control-label">Mobile No</label>
        <div class="col-md-3">
            <input type="text" class="form-control mobile" name="mobile" placeholder="Mobile No">
        </div>
        <label for="phone" class="col-md-2 control-label">Phone No</label>
        <div class="col-md-3">
            <input type="text" class="form-control phone" name="phone" placeholder="Phone No">
        </div>
    </div>
    <div class="form-group">
        <div class="col-md-offset-4">
            <button type="submit" class="btn btn-success" name="order_submit">Submit Order</button>&nbsp&nbsp
            <button type="reset" class="btn btn-danger" name="order_cancel">Cancel Order</button>
        </div>
    </div>
  </form>

jquery的:

   $(document).ready(function(){
        $('form button#more_orders_btn').on("click", function(e){
            e.preventDefault();
            var moreOrders = '';
                moreOrders += '<div class="new_order">';
                moreOrders += '<div class="form-group">';
                moreOrders += '<label for="type" class="col-md-2 control-label">Type</label>';
                moreOrders += '<div class="col-md-6">';
                moreOrders += '<select name="type[]" class="form-control type">';
                moreOrders += '<option value="">-- Select Type of Eggs --</option>';
                moreOrders += '<option value="wsmall">White Small (N550 per crate)</option>';
                moreOrders += '<option value="wmedium">White Medium (N620 per crate)</option>';
                moreOrders += '<option value="wbig">White Big (N680 per crate)</option>';
                moreOrders += '<option value="wjumbo">White Jumbo (N750 per crate)</option>';
                moreOrders += '<option value="bsmall">Brown Small (N530 per crate)</option>';
                moreOrders += '<option value="bmedium">Brown Medium (N600 per crate)</option>';
                moreOrders += '<option value="bbig">Brown Big (N650 per crate)</option>';
                moreOrders += '<option value="bjumbo">Brown Jumbo (N700 per crate)</option>';
                moreOrders += '</select>';
                moreOrders += '</div>';
                moreOrders += '</div>';
                moreOrders += '<div class="form-group">';
                moreOrders += '<label for="quant" class="col-md-2 control-label">Quantity(Crates)</label>';
                moreOrders += '<div class="col-md-6">';
                moreOrders += '<input type="text" class="form-control quant" name="quant[]" placeholder="Quantity of eggs">';
                moreOrders += '</div>';
                moreOrders += '&nbsp&nbsp<button type="button" class="btn btn-danger" id="canc_orders_btn"> X </button>';
                moreOrders += '</div></div><br/>';
                $('form#order_eggs').prepend(moreOrders);
   });

0 个答案:

没有答案