NYCPHP Meetup

NYPHP.org

[nycphp-talk] Form PRG revisited -- again

csnyder chsnyder at gmail.com
Thu Jun 14 20:41:39 EDT 2007


On 6/12/07, Cliff Hirsch <cliff at pinestream.com> wrote:
>
>  I have been testing the Form PRG pattern, and really like the way it acts
> on the user side. The back button and resubmit/reload button behave so much
> nicer, versus those ugly POSTDATA messages. But it is a bear to implement,
> unless I'm missing something as usual.


Thread is a few days old, but hopefully not moldy yet....

The pattern I use goes something like:

load request subject
define form (allowed values, expected types)
if POST, get form values from POST (validating/filtering on the way)
else get default form values from subject
if POST and no validation errors {
  use form values to update subject
  redirect 303 to subject view
}
render form (with any errors marked)

I hope that's clear enough. It's not a bear to implement, but it helps
to have a smart class for defining, validating, and rendering form
values. Pear's HTML Form was the model for mine.

I always think of unsuccessful posts as "falling through" the
validation logic, so the form can be shown again. The only thing that
breaks between successive unsuccessful form submissions is uploaded
files.

-- 
Chris Snyder
http://chxo.com/



More information about the talk mailing list