Welcome Guest, Not a member yet? Register   Sign In
Inserting multiple form fields with same name
#5

[eluser]CroNiX[/eluser]
If your array looks exactly what you stated, you could do this, where $t is your original array:
Code:
// get the keys for room_types.  It should be the same as all other fields
// since they will be equal in number for each array of form values
$keys = array_keys($t['room_types']);

// for storing newly formatted data
$insert_data = array();  

// loop through the keys (happens to be 3 with your sample data)
// and assign data to a new array based on the key
foreach($keys as $key)
{
  $insert_data[] = array(
    'room_types'    => $t['room_types'][$key],
    'room_types_sr' => $t['room_types_sr'][$key],
    'max_occupancy' => $t['max_occupancy'][$key],
    'extra_bedding' => $t['extra_bedding'][$key]
  );  
}

// get the action the form
$action = $t['insert_room_types'];  //will be 'Insert' from your example
This will create an array like you showed you wanted no matter how many additions to your form there are, assuming each new section is comprised of the 'room_types', 'room_types_sr', 'max_occupancy' and 'extra_bedding' fields.


Messages In This Thread
Inserting multiple form fields with same name - by El Forum - 03-01-2012, 07:05 PM
Inserting multiple form fields with same name - by El Forum - 03-01-2012, 11:46 PM
Inserting multiple form fields with same name - by El Forum - 03-02-2012, 08:41 AM
Inserting multiple form fields with same name - by El Forum - 03-02-2012, 08:50 AM
Inserting multiple form fields with same name - by El Forum - 03-02-2012, 11:20 AM
Inserting multiple form fields with same name - by El Forum - 03-02-2012, 09:44 PM



Theme © iAndrew 2016 - Forum software by © MyBB