Jump to content

[SOLVED] Post multiple input fields with the same name, ID, possibly in an array


Jalz

Recommended Posts

Hi Guys,

 

I have the following scenario. I have a form on html page, in which I'm posting various input/hidden fields to a response page which then alters the data within my database, which is great.

 

The problem I have though is, I have a dynamic table within my form which could have upto 6 rows with input fields which contain the samefieldnames called Address1, Address2, Country, Postcode.

 

The thing is, when I post my data to the response page, I only get the data of the 'last' row in the table, so in otherwords I get the last Address1, Address2,, Country and Postcode fields. Is it possible someone can advise me on how I can post all the data (A member may have 4 addresses) into an array as I can work out how to extract that data from the array in my response page.

 

Many Thanks for any as always.

 

Sample data below:

 


<table width="200" border="0">
<tr>
<td>Address1</td>
<td>Country</td>
<td>Postcode</td>
</tr>
<tr>
<td><input name="Address1" type="text" value="22 Bishop Crewe" id="Address1"></td>
<td><input name="Country" type="text" value="Holland" id="Country"></td>
<td><input name="Postcode" type="text" value="HH" id="Postcode"></td>
</tr>
<tr>
<td><input name="Address1" type="text" value="Cottesbrooke Park" id="Address1"></td>
<td><input name="Country" type="text" value="Scotland" id="Country"></td>
<td><input name="Postcode" type="text" value="SE4 1NR" id="Postcode"></td>
</tr>
<tr>
<td><input name="Address1" type="text" value="Trueway" id="Address1"></td>
<td><input name="Country" type="text" value="England" id="Country"></td>
<td><input name="Postcode" type="text" value="NN11 8YL" id="Postcode"></td>
</tr>
</table>



Link to comment
Share on other sites

Just name your fileds like this:

<input name="Address1[]" type="text" value="22 Bishop Crewe" id="Address1_1">

 

Notice that I added a "_1" to the ID value. You will need to increase those by one or some other method as you can't have two objects on the page with the same ID, but you can add [] to the field names to have the values returned as an array

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.