1
<div class="container" id="assignPackage">
    <table class="table table-striped table-bordered">
        <thead>
        <tr>
        <th>Group Name</th>
        <th style="text-align: center" valign="middle">Minmum Transaction Limit</th>
        <th style="text-align: center" valign="middle">Maximum Transaction Limit</th>
        <th style="text-align: center" valign="middle">Day Transaction Limit</th>
        <th style="text-align: center" valign="middle">No. of Transaction Per Day</th>
        </tr>
      </thead>
      <tbody data-bind="foreach: records">
      <tr>
        <td data-bind="text:packageName"></td>                
        <td> <div contenteditable></div> </td>
        <td> <div contenteditable></div> </td>
        <td> <div contenteditable></div> </td>
        <td> <div contenteditable></div> </td>
     </tr>
    </tbody>
  </table>    
<br><br>
 <button data-bind="click :$root.create" class="btn btn-success">Create Group</button>
<a href="<?php echo base_url(); ?>transaction_limit_setup" class="btn btn-success"><i class="icon-plus icon-white"></i><span>Cancel</span></a> 
</div>


<script type="text/javascript" charset="utf-8">
var initialData = jQuery.parseJSON('<?= $packages ?>');//data for building initial table
    var vm = function() {
    var self = this;
    self.records = ko.observableArray(initialData);
    $.each(self.records(), function(i, record){
        record.packageName = record.packageName;
    })
    self.create = function()
    {
        var values = [];
        $('#assignPackage tr').each(function(){
            var row = [],
                group = $(this).find('td:first').html(),
                columns = $(this).find('td div');

            row['group_name'] = group;

            for(var i = 0; i < columns.length; i++) {
                var value = $(columns[i]).html();

                switch(i) {
                    case 0:
                        row['min_trans_limit'] = value;
                        break;
                    case 1:
                        row['max_trans_limit'] = value;
                        break;
                    case 2:
                        row['day_trans_limit'] = value;
                        break;
                    case 3:
                        row['trans_per_day'] = value;
                        break;
                }
            }

            values.push(row);
        });

        console.log(values);

        var dataToSave = {"groupData" : values};
        $.ajax({
            type: "POST",
            data: dataToSave,
            url: "<?= base_url() ?>transaction_limit_setup/saveGroup",
            success: function(data) {
                    alert(data);
            },
        });
    }
}
ko.applyBindings(new vm());
</script>

What I want is to take all the values from an editable HTML table and post the values in a php function.Here the column Group Name is being created by data binding and other fields are editable.Now in the php function what I did is

    $var = $_POST['groupData'];
    echo $var;

I want to post the whole two dimensional array in a php function and I get the following error.

Undefined index: groupData

How can I solve this problem.

The console.log(values) display the following

[Array[0], Array[0]]0: Array[0]group_name: undefinedlength: 0__proto__: Array[0]concat: function concat() { [native code] }constructor: function Array() { [native code] }entries: function entries() { [native code] }every: function every() { [native code] }filter: function filter() { [native code] }forEach: function forEach() { [native code] }indexOf: function indexOf() { [native code] }join: function join() { [native code] }keys: function keys() { [native code] }lastIndexOf: function lastIndexOf() { [native code] }length: 0map: function map() { [native code] }pop: function pop() { [native code] }push: function push() { [native code] }reduce: function reduce() { [native code] }reduceRight: function reduceRight() { [native code] }reverse: function reverse() { [native code] }shift: function shift() { [native code] }slice: function slice() { [native code] }some: function some() { [native code] }sort: function sort() { [native code] }arguments: (...)get arguments: function ThrowTypeError() { [native code] }set arguments: function ThrowTypeError() { [native code] }caller: (...)get caller: function ThrowTypeError() { [native code] }set caller: function ThrowTypeError() { [native code] }length: 1name: "sort"__proto__: function Empty() {}<function scope>splice: function splice() { [native code] }toLocaleString: function toLocaleString() { [native code] }toString: function toString() { [native code] }unshift: function unshift() { [native code] }Symbol(Symbol.iterator): function ArrayValues() { [native code] }Symbol(Symbol.unscopables): Object__proto__: Object1: Array[0]day_trans_limit: "3"group_name: "Own Account Transfer"length: 0max_trans_limit: "2"min_trans_limit: "1"trans_per_day: "4"__proto__: Array[0]length: 2__proto__: Array[0]
jishan
  • 300
  • 1
  • 4
  • 20

0 Answers0