Looping input boxes

I’m a bit stumped with this one. Ultimately what I am looking to have is a one size fits all solution to a problem.

At the moment I have one table in a database and a single web page that gets info from the user and stores the entered info once the submit button is clicked. Dead simple. I’m about to start on building a couple more tables though, and these will use different fields and different input pages. Is there any simple way to write a submit routine that reads the name of the input boxes and the writes the contents of the input to those fields in a loop rather than hard coding it for each page? Thanks.

This is not secure since external data submitted to your web site can come from anywhere, can be anything, and cannot be trusted.

You would instead use a data driven design, where you have a data structure (array, database table query result), that defines the expected fields, any validation rules, and what processing to preform. You would then loop over this defining data structure to access the input data, validate it, and process it using general purpose code.

You would just define a different data structure for each different set of input data you want to process.

Thanks for that. Wouldn’t the name of the input boxes be set anyway in the webpage?

If I’m to follow you is your idea to set up the structure via the database table and the read the field names into the names of the input boxes when displaying the page?

Here’s an example of a data driven design - Filter search - #2 by phdr

Thanks. I’ll get a better look at that later on, but think I get the idea.

Part of the follow up issue is that each input page may be designed differently, but that’s an issue for a later day.

Thanks again.

Sponsor our Newsletter | Privacy Policy | Terms of Service