Both yesterday and earlier I was writing about some ideas on how to handle multipage forms in drupal and php in general, while keeping consistent state. OK, here is another variation on the same theme. Code will speak for itself best in this case:
.....
try {
//this detects the nessesary form step and throws an appropriate exception
init_form($request);
}
catch( FormStep1e $f ) {
//do some specific handling
}
// ... other caught form steps
catch( FormStepNe $f ) {
//do some specific handling
}
render_form($form)
....
Advantages of this approach:
Obviously this can be coded with switch() statements, but in my opinion this is a better approach, since combined with properly serialized state, we are able to significantly shorten the nessesary bootstrap process.
On a further note, the same technique can be used to handle continuations-lite in php. The prerequisite is to be able to somehow save or serialise the runtime environment. Having that, we can do something like:
try {
process_request();
}
catch( ContExn $cont){
$cont->exec()
}
process_request() restores the environment into the ContExn object and throws the exception.