Welcome Guest, Not a member yet? Register   Sign In
Weird issue with POST data when using name array
#1

I am using CI 3 and can't figure out what is causing this weird issue. I copy the form below to a plain php file then all works OK so it's definitely something to do with CI. The other forms where names are without array type work well.

The form below POSTs this data when I enter any value in any of the input box.
Array
(
   [bbs] => jhkjhkj
   [name] =>
   [description] =>
)

But if I submit the form empty then I the see the POST data as

Array
(
   [bbs] => jhkjhkj
   [name] => Array
       (
           [1] => Array
               (
                   [0] =>
               )

           [2] => Array
               (
                   [0] =>
               )

           [3] => Array
               (
                   [0] =>
               )

           [4] => Array
               (
                   [0] =>
               )

           [5] => Array
               (
                   [0] =>
               )

       )

   [description] => Array
       (
           [1] => Array
               (
                   [0] =>
               )

           [2] => Array
               (
                   [0] =>
               )

           [3] => Array
               (
                   [0] =>
               )

           [4] => Array
               (
                   [0] =>
               )

           [5] => Array
               (
                   [0] =>
               )

       )
)



The form markup is ...
<form action="myfile.php" class="form-horizontal" method="post" accept-charset="utf-8">
<input type="hidden" name="bbs" value="jhkjhkj" />
<h4>Product 1</h4>      
       <div class="form-group form-group-sm">
           <label class="col-sm-2 control-label" for="inputMenuCategoryName">Product Name</label>
           <div class="col-sm-10">
               <input type="text" name="name[1][]" value="" class="form-control" id="inputMenuCategoryName" />
                           </div>
       </div>  
       <div class="form-group">
           <label class="col-sm-2 control-label" for="inputDesc">Description</label>
           <div class="col-sm-10">
               <input type="text" name="description[1][]" value="" maxlength="255" class="form-control" id="inputDesc" />
                                           </div>
       </div>
   <h4>Product 2</h4>      
       <div class="form-group form-group-sm">
           <label class="col-sm-2 control-label" for="inputMenuCategoryName">Product Name</label>
           <div class="col-sm-10">
               <input type="text" name="name[2][]" value="" class="form-control" id="inputMenuCategoryName" />
                           </div>
       </div>  
       <div class="form-group">
           <label class="col-sm-2 control-label" for="inputDesc">Description</label>
           <div class="col-sm-10">
               <input type="text" name="description[2][]" value="" maxlength="255" class="form-control" id="inputDesc" />
                                           </div>
       </div>
   <h4>Product 3</h4>  
       <div class="form-group form-group-sm">
           <label class="col-sm-2 control-label" for="inputMenuCategoryName">Product Name</label>
           <div class="col-sm-10">
               <input type="text" name="name[3][]" value="" class="form-control" id="inputMenuCategoryName" />
                           </div>
       </div>  
       <div class="form-group">
           <label class="col-sm-2 control-label" for="inputDesc">Description</label>
           <div class="col-sm-10">
               <input type="text" name="description[3][]" value="" maxlength="255" class="form-control" id="inputDesc" />
                                           </div>
       </div>
   <h4>Product 4</h4>
       <div class="form-group form-group-sm">
           <label class="col-sm-2 control-label" for="inputMenuCategoryName">Product Name</label>
           <div class="col-sm-10">
               <input type="text" name="name[4][]" value="" class="form-control" id="inputMenuCategoryName" />
                           </div>
       </div>  
       <div class="form-group">
           <label class="col-sm-2 control-label" for="inputDesc">Description</label>
           <div class="col-sm-10">
               <input type="text" name="description[4][]" value="" maxlength="255" class="form-control" id="inputDesc" />
                                           </div>
       </div>
   <h4>Product 5</h4>
       <div class="form-group form-group-sm">
           <label class="col-sm-2 control-label" for="inputMenuCategoryName">Product Name</label>
           <div class="col-sm-10">
               <input type="text" name="name[5][]" value="" class="form-control" id="inputMenuCategoryName" />
                           </div>
       </div>  
       <div class="form-group">
           <label class="col-sm-2 control-label" for="inputDesc">Description</label>
           <div class="col-sm-10">
               <input type="text" name="description[5][]" value="" maxlength="255" class="form-control" id="inputDesc" />
                                           </div>
       </div>
           <div class="form-group form-group-sm">
           <label class="col-sm-2 control-label">&nbsp;</label>
           <div class="col-sm-10">
               <button type="submit" class="btn btn-default">Save</button>
           </div>
       </div>  
   </form>
Reply
#2

Well... it's not weird... it's only empty...
Reply
#3

(04-24-2015, 03:53 AM)Avenirer Wrote: Well... it's not weird... it's only empty...

Yes it's "only" empty even when I had filled the form. The plain php doesn't not show empty though. Any ideas how do I get it working in CI?
Reply
#4

I don't understand what you mean. It's empty in the plain PHP too:

Array
(
[bbs] => jhkjhkj
[name] =>
[description] =>
)

What do you mean by "The plain php doesn't not show empty though"? Are you refering to "bbs"? Because that one is not empty in the CI.
Reply
#5

(This post was last modified: 04-24-2015, 04:30 AM by happyape.)

(04-24-2015, 04:17 AM)Avenirer Wrote: I don't understand what you mean. It's empty in the plain PHP too:

Array
(
  [bbs] => jhkjhkj
  [name] =>
  [description] =>
)

What do you mean by "The plain php doesn't not show empty though"? Are you refering to "bbs"? Because that one is not empty in the CI.

What I mean by plain php is... Copy the form markup above and save in a new file test.php - Fill the form and press submit, you will see the values filled in the form in the the post array i.e. print_r($_POST).

However, in my CI setup it shows correct nested empty data when the form is submitted empty and when I fill in some values then I lose that nested data set and it still is empty.
Reply
#6

Then show me the controller.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB