My question doesn’t pertain to any specific piece of code that I’m working on, but is more generally related to best practices for structuring a web application, or, to be more specific, suggestions for structuring a specific kind of web application that I am working on. In this case, the application currently is not built according to any paradigm (like mvc) and I don’t know if that’s a good thing or a bad thing, given the specifics of what it does.
The application allows users to fill out web forms which are dynamically generated. In constructing these forms (using jQuery/AJAX predominantly) I have to pull admin-generated information from the database which dictates how the form is structured while also pulling user-generated information from the database which populates the form’s inputs with content. I have tried to keep the two (structure and content) conceptually separate (or at least distinct from one another) throughout the code, but I’m realizing that for the form to be generated as I want it, they kind of have to be mixed together.
For example, the forms themselves are relatively complex, giving administrators the ability to create different sections in the form which allow users to fill out multiple entries for each section (so, an administrator might create a section called “past employment” allowing a user to add multiple entries using that same collection of inputs). And so, to create the form, I start at the top and work down the hierarchy:
- create the form using the admin-generated structure;
- create the sections using the admin-generated structure;
- (in the case of multiple-entry sections) create entries using user-generated content;
- create inputs using admin-generated structure;
- populate inputs using user-generated content.
It’s the switch back and forth between looping through structure and looping through content which I think is a bit sloppy, if not conceptually, than at least in the way that I have been implementing it. It seems to me like the switch is a necessary one to make, but I’m stumped when it comes to a way of doing it elegantly. This where I think that learning a thing or two about how programmer’s generally structure these types of things would help (I’m not professionally trained…) Is there some existing paradigm or some generally accepted methodology which would help me keep all of the components of the form’s structure separate from the user-generate content which populates them while also facilitating the hierarchical construction of the form?
Thanks.
There are a bunch of javascript frameworks designed to solve your problem. Checkout backbone.js or knockout.js. Both are excellent.