18 Oct 2008 7:33 AM #1
Best practice: 1 form with dynamic content or submit 2 forms at once?
I am writing an application in wich I must be able to add components with their configuration to some objects.
All components have a common part (id, name, position,...) and a component type specific configuration which is stored in component specific database tables.
I want to create a window with a form for the complete component. The user should enter the common data and use a combobox to select the type of the component which should display the type specific part of the form.
- I read the forum and as far as I understand adding/removing fields from a form seems to be no good idea. By the way it could be that I have the same field names in the component-specific forms.
- Placing the information in fieldsets and using enable/disable + hide/show does not work either because the validation of the form works on the disabled fields, too - so if the user does not enter information for a specific component type the form will not be submitted.
- One for the common part
- One for each component type (using a card-layout to only show the selected form)
Has anybody tried to do this?
What are the problems to expect?
30 Nov 2011 5:58 PM #2
- Join Date
- Mar 2007
- Melbourne, Australia (aka GMT+10)
- Vote Rating
when you add/hide extra fields you should also add/remove the validators for those fields so that this doesn't become an issue.
You'll also want to make sure you don't end up with duplicate field names. This can be overcome by using prefixes for each 'type' of field group eg:
group = postaladdress, prefix = 'postal'
group = streetaddress, prefix = 'street'
then when you submit the form each section's data can be picked up by the logic in your server-side code.
you can easily add fields to the form before rendering (or after for that matter)... and if you put them in a group of objects to add/remove, then it makes it easier, you could submit multiple forms, but this IMHO complicates things.