xkr.us/code/javascript

FormCollect - Form encoding function

The purpose of FormCollect is to encode the data represented by all of the controls in an HTML form into a single string. Essentially it encodes the form as if it were being sent as a GET request, but because the results can be obtained before the form is submitted, one can use the encoded result for something more interesting like XHForms.

Obtaining

The latest version of the code will always be available from this page.

FormCollect.js - (2.28KB) - 2004-10-20

Usage

After including the script in your HTML page, you only need to call the FormCollect passing in a valid form reference.

A valid form reference can be obtained a number of ways, but two of the simplest ways are:

  1. <form onsubmit="alert(FormCollect(this));return false;" ...> -- which is used in the demo.
  2. alert(FormCollect(document.getElementById("formsId"))); -- referencing the form directly by its id.

About

FormCollect trys to duplicate conventional browser behavior by encoding almost all form elements (exceptions described under Known Issues). This means that disabled controls will not be encoded, and only valid form element types will be considered.

Demo

For a simple demonstration, see the demo page.

Known Issues

References

W3C - Successful controls