1

On one of my pages I pull a table of data from the database and display it to the user, giving them the option to update the values for each row. My question is what is the best way to do this?

Currently, i'm stuck between two options. Option one is to display one form with all of the inputs. My other idea was to have each row be a form itself. Is there an advantage to one over the other? Right now i'm leaning towards the the latter of the two - as it seems like much less overhead to only POST data for one row as opposed to all of them for a single update.

2 Answers 2

2

You should certainly define separate forms for every row. No need to send all the data all the time.

Semantically, they are also separate forms. It is also easier to handle the data you get on the server side.

Sign up to request clarification or add additional context in comments.

2 Comments

So if I use this method, I would have $(.form).submit(function...) to listen to any form thats submitted. I would probably set the id to be the objid of the row from the data to ensure uniqueness - could I then reference it with jquery in the callback by using this.id, and then getting the children of the form (labels) to get the values?
@tdk2fe You can use a common submit event handler for all the forms, yes. You can simply store the IDs (for the objects) in a hidden form input. Simply grab the items with .serialize(), post them, and in the callback this should refer to the form. Well, without seeing any code, talking theoretically.
1

you could set it up so that when a record is clicked the data for that record(id,name,other...) are loaded into a form in a jQuery ui dialog then have two buttons on the dialog (save,cancel)

Save: use ajax to send the data to a php data helper which will update the record in the database

cancel: clear the fields in the form and close the dialog

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.