P
Paxton
At the risk of being told "If it ain't broke, don't fix it", my code works,
but is ugly.
Part of the admin site I'm working on at the moment includes a facility for
users to enter Formulations (recipes for making cosmetics etc) in 3 stages:
Stage 1: basic info such as title, method etc and number of Phases (steps in
recipe).
Stage 2: dynamically generated form containing the exact number of phases as
textboxes, depending on the number entered in stage 1. Phases are labelled
A, B, C...etc. They rarely exceed 8 in total. In each text box, the user
enters the number of ingredients per phase.
Stage 3: dynamically generated form offering the correct number of text
boxes per phase for users to enter ingredients per phase.
These inputs are named IngredientsA, IngredientsB etc - depending on the
phase they belong to. Of course, if there is more than one ingredients per
phase, they are posted back as a comma-delimited list.
At the moment, I test for the existence of each phase's ingredients:
if len(Request.Form("IngredientsA"))>0 then
....process the data
end if
if len(Request.Form("IngredientsB"))>0 then
....process the data
end if
if len(Request.Form("IngredientsC"))>0 then
....process the data
up to IngredientsJ.
Everything works as I would like it to, but I'm sure there must be a better
way of iterating through these form fields than this. Coding to cater for
up to 10 possible phases is repetitive, and is over 200 lines long.
Elegant, it ain't! Anyone got any ideas?
P
but is ugly.
Part of the admin site I'm working on at the moment includes a facility for
users to enter Formulations (recipes for making cosmetics etc) in 3 stages:
Stage 1: basic info such as title, method etc and number of Phases (steps in
recipe).
Stage 2: dynamically generated form containing the exact number of phases as
textboxes, depending on the number entered in stage 1. Phases are labelled
A, B, C...etc. They rarely exceed 8 in total. In each text box, the user
enters the number of ingredients per phase.
Stage 3: dynamically generated form offering the correct number of text
boxes per phase for users to enter ingredients per phase.
These inputs are named IngredientsA, IngredientsB etc - depending on the
phase they belong to. Of course, if there is more than one ingredients per
phase, they are posted back as a comma-delimited list.
At the moment, I test for the existence of each phase's ingredients:
if len(Request.Form("IngredientsA"))>0 then
....process the data
end if
if len(Request.Form("IngredientsB"))>0 then
....process the data
end if
if len(Request.Form("IngredientsC"))>0 then
....process the data
up to IngredientsJ.
Everything works as I would like it to, but I'm sure there must be a better
way of iterating through these form fields than this. Coding to cater for
up to 10 possible phases is repetitive, and is over 200 lines long.
Elegant, it ain't! Anyone got any ideas?
P