ValidForm.rb

Path: ValidForm.rb
Last Update: Fri Mar 12 12:23:44 MST 2004

Classes for working with ValidForm/ValidForm::Field objects of all types, specifying their labels, values, and validation rules.

The ValidForm library allows you to specify a form fully in Ruby code, along with validation rules for that data. You can then easily emit an HTML version of that form (either fully—with a single method call—or in controlled pieces) which includes the hooks needed for client-side validation using FormAutoValidate. Because client-side isn’t enough, you can then re-validate the data server-side in Ruby (again with a single method call to pull the submitted values into the form and validate them). And finally, re-emitting the html for an already-validated form emits CSS hooks and validation error messages.

ValidFormTest.tar.gz is a fully-functioning mod_ruby/eRuby example, with files showing how to:

  • Create a complex form, with various validation rules.
  • Emit the HTML for that form.
  • Use CSS to style the semantic markup in non-trivial ways. (At least for Safari/Mozilla…I have no idea if IEWin supports this particular example properly.)
  • View the client-side library in action.
  • Load the values back into the form server-side, re-validate, and re-emit new HTML noting the errors.

One caveat: the hooks needed for FormAutoValidate produce ‘invalid’ HTML; that is, the output will no longer validate as HTML4 because of the custom attributes put into the fields. This should cause no problems for the browser, as in all other ways the output should be HTML4Strict compliant.

Include ../ValidForm_html.rb to be able to transform these fields into HTML equivalent.

Relies on basiclibrary.rb for WriteOnceHash and Time#custom_format

Author:Gavin Kistner (!@phrogz.net)
Copyright:Copyright ©2004 Gavin Kistner
License:See Phrogz.net/JS/_ReuseLicense.txt for details
Version:1.1
Full Code:../ValidForm.rb

Required files

basiclibrary   time  

Classes and Modules

Class ValidForm
  ::Module ValidForm::Container
  ::Class ValidForm::CheckboxSet
  ::Class ValidForm::Field
  ::Class ValidForm::Fieldset
  ::Class ValidForm::Hidden
  ::Class ValidForm::Option
  ::Class ValidForm::OptionSet
  ::Class ValidForm::Password
  ::Class ValidForm::RadioSet
  ::Class ValidForm::Reset
  ::Class ValidForm::Submit
  ::Class ValidForm::Text
  ::Class ValidForm::ValidationError

[Validate]