Tableking
Tableking

Reputation: 268

What Is Best Way To Handle A Form With Over 100 Input Fields?

Hey all. I have a project that will require user input of anywhere from 100-500 form input fields that will then be entered into a database table. I need some advice on what is the best method to handle so many fields.

Would it be best to have the user enter 10 at a time into the database and then ask, "Would you like to input more data?" and then update the table with the added entries?

or

Could I hold an array of input in a session while the user enters 10 in succession and then have all of the fields entered into the database at once?

Thanks for replies.

Upvotes: 1

Views: 1824

Answers (3)

mhughes
mhughes

Reputation: 630

Beware, common hardening solutions for php, for example suhosin, limit the number of maximum number of post variables. It's common in shared hostings, and might fail silently.

Also, consider using array syntax for post variables..

eg. inputs with names like: "user[]" will populate the $_POST variable as an array.

Upvotes: 0

CryptoMonkey
CryptoMonkey

Reputation: 163

well, aside from the question about when to save the data, for large forms like this, I like to double up the input tags with a matching hidden input tag. For example, <input name='test' > I will also create <input type='hidden' name='test-orig' value='orig-value' /> and then on the server I will compare the form input tag with the hidden original and see if the data has been altered. This will keep you doing INSERT / UPDATE's on only the data elements that have changed and not INSERT/UPDATE every single value.

Also, make sure to study the ON DUPLICATE KEY UPDATE syntax because it's just so darn helpful. Make sure you normalize your database tables and only update the data elements that have changed.

For a form of this size, instead of storing the data in the PHP session I would save it straight to the database in logical blocks, this will keep the user from losing their information in case their session times out (which could happen if the form is huge). Then add a pending record flag to your table structure to determine when a user has saved the entire record vs a partial save.

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798764

I'd have some sort of "wizard" interface for inputting the data, storing the pages in the session as the user goes along. So yes, your latter idea is sound.

Upvotes: 2

Related Questions