Welcome Guest, Not a member yet? Register   Sign In
How To Add Many Identical Fields Into a Form for Submission
#1

[eluser]vincej[/eluser]
Hi - I have a simple HTML form which presents on each row a location with 4 dates.

The array and foreach loop which generates the HTML appears to be correct. I.e. if I look into the HTML source I see every location with every date including the vital hidden data which uniquely identifies each specific date.


My problem appears to be that because each row in the source HTML has the same name (see source below), when I do a 'submit', the POST array gets overwritten and hence only the very last row is now delivered into my model.

HTML Source extract:

Code:
<td width="100" align="center">4
&lt;input type="hidden" name="locationid" value="4" /&gt;
</td>
   <td width="100" align="center">&lt;input type="text" name="location" value="Collingwood" size="20"  /&gt;&lt;/td>
   <td width="100">&lt;input type="text" name="1293704800" value="30 Dec 2010" size="15" theIDs="2"  /&gt;&lt;/td>
   <td width="100">&lt;input type="text" name="1311704800" value="26 Jul 2011" size="15" theIDs="1"  /&gt;&lt;/td>
   <td width="100">&lt;input type="text" name="1315704800" value="10 Sep 2011" size="15" theIDs="3"  /&gt;&lt;/td>
   <td width="100">&lt;input type="text" name="1337704800" value="22 May 2012" size="15" theIDs="4"  /&gt;&lt;/td>
   <td width="150"> <a href="http://localhost/countrylane/index.php/admin/pickup_detail/deletelocation/Collingwood">Delete</a></td>
  
</tr>
     <tr align="center">
<td width="100" align="center">5
&lt;input type="hidden" name="locationid" value="5" /&gt;
</td>
   <td width="100" align="center">&lt;input type="text" name="location" value="Varsity" size="20"  /&gt;&lt;/td>
   <td width="100">&lt;input type="text" name="1331704800" value="14 Mar 2012" size="15" theIDs="5"  /&gt;&lt;/td>
   <td width="100">&lt;input type="text" name="1334704800" value="17 Apr 2012" size="15" theIDs="6"  /&gt;&lt;/td>
   <td width="100">&lt;input type="text" name="1337704800" value="22 May 2012" size="15" theIDs="7"  /&gt;&lt;/td>
   <td width="100">&lt;input type="text" name="1339704800" value="14 Jun 2012" size="15" theIDs="8"  /&gt;&lt;/td>
   <td width="150"> <a href="http://localhost/countrylane/index.php/admin/pickup_detail/deletelocation/Varsity">Delete</a></td>
  
</tr>


My second problem is that 'theIDs' are all being ignored by my model.

I expect that possibly I should rework my model to do multiple DB updates or do a Batch Update ???


Model:

Code:
function Updatelocation(){
  $locationid = $_POST['locationid'];  
  $data = array(
  'locationid' => db_clean($locationid),
  'puid' => db_clean($_POST['theIDs[0]']),
  'puid' => db_clean($_POST['theIDs[1]']),
  'puid' => db_clean($_POST['theIDs[2]']),
  'puid' => db_clean($_POST['theIDs[3]']),
  'dates' => db_clean(strtotime($_POST[$theDates[0]])),
  'dates' => db_clean(strtotime($_POST[$theDates[1]])),
  'dates' => db_clean(strtotime($_POST[$theDates[2]])),
  'dates' => db_clean(strtotime($_POST[$theDates[3]]))
    );
   $this->db->where('locationid', $locationid);
    $this->db->update('pudates',$data);
}


sorry if all this sounds a bit of a noob question,

Many Many Thanks Vincej


Messages In This Thread
How To Add Many Identical Fields Into a Form for Submission - by El Forum - 03-22-2012, 11:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB