Reputation: 2413
I'm looking for the best practice for saving a dynamic HTML form. The fields of the form are added the the page by AJAX. Each field is similar to:
<input type="text" name="field_12" />
Where, in this case, "12" is the primary key for the field in the database.
I plan to send these fields via POST back to the server for saving. When it's time to save, I do not know the name
attributes that will be coming over.
I can think of two ways to do this.
Have a hidden item with a list of field ids. I can then parse it before doing the inserts.
<input type="hidden" name="fieldIds" value="1,2,12,14" />
Query the database for the expected field ids, then do the inserts based on that.
I can see advantages and disadvantages of both scenarios. What is the best practice in this situation?
I'm using classic ASP on an IIS server, although, I don't think that's a factor here.
Upvotes: 0
Views: 360
Reputation: 1088
make input fields like
<input type="hidden" name="field[]" value="12" />
<input type="hidden" name="field[]" value="13" />
<input type="hidden" name="field[]" value="14" />
...
it will become array on server side
and loop it through, then insert
Upvotes: 1