I need to create a web form that functions as a skills checklist. The user will select a 'specialty' from a drop down and based upon that selection, a list (with as many as 50 radio selections) will be presented to the user. I'm trying to figure out the best way to do this in terms of performance and maintainability.

1) I can write the skills list as a huge single form and then use jQuery to to show and hide the elements based upon the drop down selection. However, this may lead to very long page load times since there may be upwards of 1000 fields in the form.

2) I could gather the 'specialty' information at an earlier time, then load it at run time and based upon that, run another query for all the fields I will need from the database and build the form in a foreach loop. This means that there will be upwards of 30 queries in the form and an extremely complex submit handler to insert all of the entered data into the database.

Any thoughts on the best way to accomplish this? This is part of a large web application with many different sections and performance and maintainability is a huge consideration.



Do you know that Webform now supports conditional form items from the now merged webform conditionals module?

You can then manage this form like any drupal webform and show/hide child pieces of the form based on selection rules. If your form is huge good luck the conditional page/logic settings can get huuuge and cumbersome.

If you want to this in php code yourself I recommend this tutorial using the Ctools based Multistep Form. I've made multi-step forms using native drupal node forms -- just the stepping logic is very ugly. This is clear and precise using a multi-step ctools form.

You could even show/hide stuff I believe on 1 page of the form usig FAPI #states API. A tutorial explaining #states provided by Shane Graham is on this blog post. Also review this for more complicated XOR type logic in forms here on d.stackexchange: Multiple Values to Trigger #states

| improve this answer | |
  • It has to be done in php. The problem #states is that when the page refreshes the state is lost and since this is a long form, the state must be retained for the user expereince. By using jquery, i can load the form after the my autosave loads and thus keep the state of the select. However, the jQuery (and #states) slows as the number of form elements grows. Multi-step form is problematic because the client wants the user to fill out this section in any order they wish and to be able to use navigation buttons and links to move throughout.This makes keeping the counter value straight difficult. – user19321 Jul 17 '13 at 22:36
  • then just pick your poison. Unless your Google -- the choice based on performance is wrong; do whatever is easiest for you to program. Optimize later. – tenken Jul 17 '13 at 22:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.