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

[eluser]sarcastron[/eluser]
You may want to consider using a multidimensional array for the inputs on the HTML side. Then you could use a foreach loop to insert them or build the an array to sort them. The HTML for the form (be it generated via PHP or jQuery) would look sort of like this:

Code:
<h3>First Room</h3>
<p><label for="room_types">Room type</label>&lt;input type="text" name="rooms[1][room_type]" /&gt;&lt;/p>
<p><label for="room_types_mk">Room type SR</label>&lt;input type="text" name="rooms[1][room_types_sr]" /&gt;&lt;/p>
<p><label for="max_occupancy">Max Occuancy</label>&lt;input type="text" name="rooms[1][max_occupancy]" /&gt;&lt;/p>
<p><label for="extra_bedding">Extra Bedding</label>&lt;input type="text" name="rooms[1][extra_bedding]" /&gt;&lt;/p>

<h3>Second Room</h3>
<p><label for="room_types">Room type</label>&lt;input type="text" name="rooms[2][room_type]" /&gt;&lt;/p>
<p><label for="room_types_mk">Room type SR</label>&lt;input type="text" name="rooms[2][room_types_sr]" /&gt;&lt;/p>
<p><label for="max_occupancy">Max Occuancy</label>&lt;input type="text" name="rooms[2][max_occupancy]" /&gt;&lt;/p>
<p><label for="extra_bedding">Extra Bedding</label>&lt;input type="text" name="rooms[2][extra_bedding]" /&gt;&lt;/p>

<h3>Third Room</h3>
<p><label for="room_types">Room type</label>&lt;input type="text" name="rooms[3][room_type]" /&gt;&lt;/p>
<p><label for="room_types_mk">Room type SR</label>&lt;input type="text" name="rooms[3][room_types_sr]" /&gt;&lt;/p>
<p><label for="max_occupancy">Max Occuancy</label>&lt;input type="text" name="rooms[3][max_occupancy]" /&gt;&lt;/p>
<p><label for="extra_bedding">Extra Bedding</label>&lt;input type="text" name="rooms[3][extra_bedding]" /&gt;&lt;/p>

You want to adjust the FOR attribute in your labels and give your inputs unique ID attributes as well, but that's beside the point.

Then you could use something like this in the controller:

Code:
$thePost = $this->input->post();
$insert_array = $thePost['rooms'];

This should give you a multidimensional array that you could use and you wouldn't have to worry about sorting the array since the sorting was done before the POST was sent. I hope this is helpful.


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