Enumerating Request.Form() Data

Audience Level

Beginner and above

Introduction

This JScript ASP function enumerates the Request.Form() collection and returns every key name (including duplicates) and key value that was submitted to the server. It can be used as a debugging tool, or with a modification described below, can be used for HTTP state maintenance by embedding data from a previous POST request into the current page. It can be easily modified to work with any collection object, not just Request.Form.

The Basic Function

function getEnumerateFormData() {
    var objO = [];
    for (var e = new Enumerator(Request.Form); !e.atEnd(); e.moveNext()) {
        var key     = e.item();
        var count   = Request.Form(key).Count;
        for (var i=1; i<=count; ++i) {
            objO.push(Server.HTMLEncode(key) + "=" + Server.HTMLEncode(Request.Form(key).Item(i)));
        }
    }
    return objO.join("\r\n");
}

A Function To Return All Posted Data As Hidden Form Fields

function getEnumerateFormDataAsHiddenFields() {
    var objO = [];
    for (var e = new Enumerator(Request.Form); !e.atEnd(); e.moveNext()) {
        var key     = e.item();
        var count   = Request.Form(key).Count;
        for (var i=1; i<=count; ++i) {
            objO.push("<input type=\"hidden\" name=\"" + Server.HTMLEncode(key) + "\" value=\"" + Server.HTMLEncode(Request.Form(key).Item(i)) + "\">");
        }
    }
    return objO.join("\r\n");
}

Advertisement

Feedback

Voting Panel
Is this useful?
or
Did you find any bugs?
or
Did it solve your programming problem?
or
Rate this script: (0=poor, 5=very good)
Answers are anonymous, only the combined totals are stored. Uses cookies.