Please report any problems found to me ASAP, so I may fix them and build another release.
I get literally hundreds of emails asking how to use these functions, and questions
relating to them, etc. If you have any enquiries regarding these scripts, email me,
but please allow up to 36 Hours for a response.
If you are interested in functions similar to the above but allow interaction
with databases, then these will be available soon.
I hope you find these functions to be as useful and time-saving as everyone else,
and use them to their fullest potential. I TRULY APPRECIATE ANY FEEDBACK.
The GetVars function, will ONLY work with the VBScripting Engine ver 5.x
updates to the scripting engine for win 9x, and NT 4.0 are available from the
microsoft site:-
www.microsoft.com/scripting.
Bear in mind, I always find it nice to get a mention where my functions are used
but I do not require it. I am more willing to help those and supply new updated
functions to those who acknowledge me in either content, or comments with the
page source.
Good Luck, and Happy Coding!!!
Rob Collyer (aka ASPwiz)
ASPwiz@hotmail.com
All of these functions will come into their own when dealing with multiple page
forms.
In the Examples given, remember to replace the <$ and $> tags
with the proper open/close ASP tags.
Function No.1
This first function will get variables from forms and/or querystrings and/or cookies.
The function will set VBScript variables with identical names, and equal values.
This saves the tedious task of request.form("this") request.Querystring("that"),
and request.cookies("the_other").
Usage:- Call SetVars(StrType)
Where 'StrType' is a string value of either, "form",
"querystring", "cookies",or "all"
<%
Function SetVars(StrType)
If lcase(StrType) = "form" or lcase(strType) = "all" then
For Each Field in Request.Form
TheString = Field & "=Request.Form(""" _
& Field & """)"
EXECUTE(TheString)
Next
End If
If lcase(StrType) = "querystring" or lcase(strType) = "all" then
For Each Field in Request.Querystring
TheString= Field & "=Request.Querystring(""" _
& Field & """)"
EXECUTE(TheString)
Next
End If
If lcase(StrType) = "cookies" or lcase(strType) = "all" then
For Each Field in Request.Cookies
TheString= Field & "=Request.Cookies(""" _
& Field & """)"
EXECUTE(TheString)
Next
End If
END Function
%>
Function No.2
This second function will get variables from forms and/or querystrings and/or cookies,
and write them in a form as hidden fields. This is very useful when dealing with
multiple page forms.
The function must be called prior to the </form> tag, so it can include the hidden fields
This saves the tedious task of: <Input type="hidden" name="field1" value="value1">, etc
This saves a lot of work when passing many, many variables.
Usage:- Call IncludeHidden(StrType, IGNORELIST)
Where 'StrType' is a string value of either,
"form", "querystring", "cookies", or "all"
and 'IGNORELIST' is a comma seperated string of field names to ignore. (Case INsensitive)
EXAMPLE:- To include all values submitted to the page via
a form, within the second form as form fields.
<Form Action="Form3.asp" Method="post">
<Input type="text" name="whatever">
<!-- More fields as appropriate-->
<!-- ............ -->
<$ Call IncludeHidden("Form", "") $>
<Input type="submit">
</Form>
If you wanted to exclude a field called 'whatever' (Perhaps the page
receives its own data back at some stage).
Then you could use:- <$ Call IncludeHidden("Form", "whatever") $>
and the hidden form field named 'whatever' won't be included.
<%
Function IncludeHidden(StrType, IGNORELIST)
If lcase(StrType) = "form" or lcase(StrType) = "all" then
For each Field in Request.Form
If NOT Onlist(Field, IGNORELIST) Then
TheString="<Input Type=""HIDDEN"" Name=""" _
& Field & """ Value="""
StrValue=Request.Form(Field)
TheString=TheString + cstr(StrValue) & """>"
TheString=TheString & VbCrLf
Response.Write TheString
End If
Next
End If
If lcase(StrType) = "querystring" or lcase(StrType) = "all" then
For each Field in Request.Querystring
If NOT Onlist(Field, IGNORELIST) Then
TheString="<Input Type=""HIDDEN"" Name=""" _
& Field & """ Value="""
StrValue=Request.Querystring(Field)
TheString=TheString + cstr(StrValue) & """>"
TheString=TheString & VbCrLf
Response.Write TheString
End If
Next
End If
If lcase(StrType) = "cookies" or lcase(StrType) = "all" then
For each Field in Request.Cookies
If NOT Onlist(Field, IGNORELIST) Then
TheString="<Input Type=""HIDDEN"" Name=""" _
& Field & """ Value="""
StrValue=Request.Cookies(Field)
TheString=TheString + cstr(StrValue) & """>"
TheString=TheString & VbCrLf
Response.Write TheString
End If
Next
End If
END Function
%>
Function No.3
This third function will get variables from forms and/or querystrings and/or cookies,
and write them in a link as a querystring. This is very useful when dealing with
online applications that pass lots of variables this way.
The function must be called in a specific way, example given below.
Usage:- Call WriteQueryString(StrType, IGNORELIST)
Where 'StrType' is a string value of either, "form",
"querystring", "cookies",
or "all" and 'IGNORELIST' is a comma seperated string
of field names to ignore. (Case INsensitive)
EXAMPLE:- To write all values submitted to the page via a querystring.
<A href="APage.asp?<$Call WriteQueryString("querystring","")$>">
Click Here
</a>
If you wanted to exclude a field for whatever reason, then follow the example
as for the 'IncludeHidden' function.
<%
Function WriteQueryString(StrType, IGNORELIST)
If lcase(StrType) = "form" or lcase(StrType) = "all" then
For each Field in Request.Form
If NOT Onlist(Field, IGNORELIST) Then
TheString=TheString+Field&"="
TheString=TheString & Request.Form(Field)
TheString=TheString & "&"
End If
Next
End if
If lcase(StrType) = "querystring" or lcase(StrType) = "all" then
For each Field in Request.Querystring
If NOT Onlist(Field, IGNORELIST) Then
TheString=TheString+Field&"="
TheString=TheString & Request.Querystring(Field)
TheString=TheString & "&"
End If
Next
End if
If lcase(StrType) = "cookies" or lcase(StrType) = "all" then
For each Field in Request.Cookies
If NOT Onlist(Field, IGNORELIST) Then
TheString=TheString+Field&"="
TheString=TheString & Request.Cookies(Field)
TheString=TheString & "&"
End If
Next
End if
If right(TheString,1)="&" Then
TheString=Left(TheString,Len(TheString)-1)
Response.Write TheString
End if
END Function
%>