Topics

programming

php drupal scheme scheming macros design patterns da la

design

design css

random thoughts

scribbles

alter ego

other me 'em that link us my space me linked in

Collections

Programmable web
PHP design patterns

Similar things

  • Emulating closures in PHP
  • Some ways to use saved state with closures in php
  • Wizardy, druidy, wiz
  • Random thoughts on web application internals
  • x|s|p expressions mixing
  • aspects and honey in php
  • Partial evaluation and generics in php
  • Scoped php functions or more ways to abuse php
  • Updated design pattern collection
  • Poor man's macro programming in php
Home » blogs » vlado's blog

An alternative for multipage forms

Submitted by vlado on Thu, 2006-03-23 07:57.php | programming

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:

  • Natural program order, even for coding across requests
  • obvious, switch-like semantics
  • intuitive and explicit flow tracking

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.

vlado's blog | add new comment
Home » blogs » vlado's blog

dikini.net

spreading confusion by accident since 1970