tags:

views:

112

answers:

1

In a html form, I'm displaying multiple records from a table, ready for update.

Right now I use: name=<column-name>_<pk-id> value=<value> for the fields. Then in my python-script I go for:

for key in form.keys():
    if key.startswith('<name-A>_'):
        update <table> set <name-A> = <value> where pk=<pk-id>
    if key.startswith('<name-B>_'):
        update <table> set <name-B> = <value> where pk=<pk-id>

Is there a more 'organic' way to handle multi-record forms?

+1  A: 

In java apps, it's common to JSONify the name.

<input name="records[pk].fieldName"/>

pk being the primary key of the row and fieldName the field. Of course most frameworks handle this transparently. Each record ends up as a instance of a class with a property for each field, all of which are put into a list called "records". You may have to write some sort of interpreter, but that shouldn't be too hard.

sblundy