views:

42

answers:

1

I am using Jquery dynamic form plugin to generate dynamic fields in one of the forms I have in the application. the plugin works fine and it creates the field. I am still confused on what the best way is to get the form field values.

foreach ($this->input->post('product_item') as $key => $value) {
     foreach($value as $element)
      {
        print_r($element);
      }
}

returns

Array ( [color0] => red [size0] => s [quantity0] => 2 ) Array ( [color0] => green [size0] => m [quantity0] => 2 )

How do I get specific array value to store it in the Database.for e.g access Array ( [color0] => red [size0] => s [quantity0] => 2 ) and store it's value in Database.

Thanks for your time.

A: 

By looking at this, you already know how to get the field values, just continue to recurse the array.

Would this not get you the desired result:

foreach ($this->input->post('product_item') as $key => $value) {
 foreach($value as $element)
  {
    $color = $element['color0'];
    $size = $element['size0'];
    $quantity = $element['quantity0'];
     mysql_query("INSERT INTO table (Color, Size, Quantity) VALUES ('$color', '$size', '$quantity')");
  }

}

In your example, you have the array keys in both arrays end in 0, these should increment, right?

kmfk
Thanks. I did get the problem resolved by the solution you mentioned. The jQuery dynamic form plugin does not increment the 0 for the field, but creates a new array for each dynamic field.
Sunil Shenoy