This is just an
of how I would go about doing it.
Code:
// define some constants
define ('INITIAL', 0);
define ('SET_MAIN_CATEGORY', 1);
define ('SET_SUB_CATEGORY', 2);
define ('FAILED_VALIDATION', 3);
define ('ALL_OK', 4);
$state = INITIAL;
// work out how we got here
if (submit buton was pressed)
{
if (main category has not been selected)
{
$state = SET_MAIN_CATEGORY;
}
else
{
if (sub category has not been selected)
{
$state = SET_SUB_CATEGORY;
}
else
{
if (all fields pass validation)
{
$state = ALL_OK;
}
else
{
$state = FAILED_VALIDATION;
}
}
}
}
// now build the appropriate drop-downs
switch ($state)
{
case INITIAL:
build main category list with no selection
build empty sub category list with no selection
break;
case SET_MAIN_CATEGORY:
build main category list with no selection
build empty sub category list with no selection
break;
case SET_SUB_CATEGORY:
build main category list with selection = posted main cateogry
build sub category list with no selection based on posted main category
break;
case FAILED_VALIDATION:
build main category list with selection = posted main cateogry
build sub category list with selection = posted sub category, based on posted main category
break;
case ALL_OK:
redirect user to new page
break;
default:
// some unkonwn state - so do the same as for an initial state, just to be on the safe side
build main category list with no selection
build empty sub category list with no selection
break;
}
build and display form here, using any data available from the posted variables
Hope this gives you a starting point
Bookmarks