tags:

views:

53

answers:

4

A department at my university has asked the CS department to make them a site that will allow faculty on campus to RSVP for an appreciation breakfast that is held once a year. They then want to be able to pull up all who have registered for the event from some administration page.

This isn't really a problem, and I can create a simple form and store the results in a MySQL db we have here.

However, what I'm not sure about, is they want it to be "customizable". That is, they want to not only be able to change the text of RSVP questions, but they also want to be able to add more questions to the form. They also want to be able to customize what the banner image is.

Is there any library or technique out there that would make this kind of customization a little less painful? How can I allow them to be able to configure some arbitrary number of form fields and still persist them in the database appropriately?

+1  A: 

The typolight cms holds such a form generator. You could either use it for that purpose or take a look at it's source since it's licensed under the LGPL.

tDo
I took a look at this cms, it is very interesting. I will have to investigate further.
Vincent Ramdhanie
+1  A: 

Sounds like they need a CMS. You can look at existing Joomla or Drupal but they are extremely "large" compared to the simple app you are describing. So if you were doing it yourself then you can consider something along the lines of creating a table that stores fields.

Fieldid   fieldname  fieldlabel ...
  1         fname      First Name
  2         lname      Last Name
  3         meat       Do you like Meat?
...

Then you can create a form that allows them to add new fields as they see fit. Then to generate the form you loop through this table and create an input for each field found.

When they submit the form you can loop through the list of fields to get the values and store it in another table.

 Answerid    Fieldid    Answer
   1            1         Jack
   2            2         Black
   3            3         Yes

  ....

Of course this is a simplistic look, I think it would grow a lot more complex as you progress.

Vincent Ramdhanie
A: 

Why not store the questions in your database and make another administrative page that would allow them to add/remove/edit the questions? You could store the banner image somewhere as well.

kitchen
A: 

I would create a table with columns like this (example, add fields as needed).

  • UID (Pri key)
  • Form Number
  • Input Label.
  • Type of input
  • Default Value

Then, when you use a form, you only have a form number. Write a function to grab elements from this table and create an input based on each - how you input this data in the first place will require another form. This way you can have variable length fields. You could even have a templates table and save forms in there, too.

I'd store form configuration in a separate table.

As always, verify input correctly - that'll be crucial here if you are rendering HTML from user input, and consider stored procedures.

Ninefingers