Two Functions:ReadFormVariables and SendHiddenFormFields<% '=================================================== 'The Functions below were developed by Robert Collyer:- ASPwiz@hotmail.com ' 'These scripts will now make variables live well beyond the page scope and make the debugging 'process of passing variables between pages just a memory. 'All scripts are really flexible and work on form elements, querystrings and cookies. ' '==================================================== 'The first Funtion-'GetVariables(type1, type2)' can be used in place of the very common:- 'var1=request.form("var1") 'var2=request.form("var2") 'var3=request.form("var3") 'var4=request.form("var4") 'var5=request.form("var5") 'and likewise for reading in querystrings and cookies ' 'Taking FORMS as an example: 'You simply now just call the function, and all vbscript values are set to match those 'posted from a form. This sounds great, and it is but the vbscript variables are named 'identically to the form/querystring/cookie variable names (this is usually a good thing) 'If for example a form contained a text box that is named 'Surname', 'and after submitting the form, the following page called upon the 'GetVariables("form",0)' 'function, VBScript would now have access to a variable called Surname containing the value 'of whatever the user entered into the textbox. It will loop through ALL form variables, 'setting the VBScript equivelents. ' ' '=================================================== 'The Second Function-'SaveAsFormFields(type1, type2)' is very useful for those occasions where 'you need to read in all the form/querystring/cookie values, and include them within another form as 'hidden fields. Reasons to this could include multiple page forms and also when a user 'enters data incorrectly on a form, and you want to post the data back for editing, etc ' '=================================================== 'The Third Function-'SaveAsCookie(type1, type2) will pass the variables stated by type1 and type2 'to a cookie on the clients computer. You can retrieve this cookie and read the variables 'back in on another page using:- Call GetVariables("cookies",0)
'===================================================== 'Please email ASPwiz@hotmail.com with all feedback. (Including bugs if any) 'I do not require a mention if you use this code (Unless the source is published), it 'is supplied purely because 'I know how much of a pain in the arse the long way round is and I feel sorry for those 'who are non-the-wiser. Please feel free to distribute this as far and as wide as you like. 'This message will self destruct, etc...... '==================================================
'*//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//** '================================================== ' Call the following function with: ' ' Call GetVariables("TYPE1", "TYPE2") replacing TYPE1 and TYPE2 with: form, cookies or querystring. ' ' Alternatively the function may be called as follows: ' Call GetVariables("ALL", 0) calling the function in this way performs all three types. '==================================================== function GetVariables(type1,type2) if lcase(type1)="form" or lcase(type2)="form" or lcase(type1)="all" then For Each Field In Request.Form TheString = Field & "=Request.Form(""" & Field & """)" Execute(TheString)'Executes the command contained in the string(This will set all VBScript variables) Next end if if lcase(type1)="cookies" or lcase(type2)="cookies" or lcase(type1)="all" then For Each Field In Request.cookies TheString = Field & "=Request.cookies(""" & Field & """)" Execute(TheString)'Executes the command contained in the string(This will set all VBScript variables) Next end if if lcase(type1)="querystring" or lcase(type2)="querystring" or lcase(type1)="all" then For Each Field In Request.querystring TheString = Field & "=Request.querystring(""" & Field & """)" Execute(TheString)'Executes the command contained in the string(This will set all VBScript variables) Next end if END function
'*//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**
'==================================================== ' Call the following function with: ' Call SaveAsFormFields("TYPE1", "TYPE2") replacing TYPE1 and TYPE2 with: form, cookies or querystring. ' 'Lastly the function may be also be called as follows: 'Call SaveAsFormFields("ALL", 0) calling the function in this way performs all three types. '====================================================
function SaveAsFormFields (type1, type2) if lcase(type1)="form" or lcase(type2)="form" or lcase(type1)="all" then For Each Field In Request.Form TheString="<input type=""hidden"" name=""" & Field & """ value=""" Value=Request.Form(Field) Thestring=TheString + cstr(Value) & """>" & vbcrlf Response.Write TheString Next end if if lcase(type1)="cookies" or lcase(type2)="cookies" or lcase(type1)="all" then For Each Field In Request.cookies TheString="<input type=""hidden"" name=""" & Field & """ value=""" Value=Request.cookies(Field) Thestring=TheString + cstr(Value) & """>" & vbcrlf Response.Write TheString Next end if if lcase(type1)="querystring" or lcase(type2)="querystring" or lcase(type1)="all" then For Each Field In Request.Querystring TheString="<input type=""hidden"" name=""" & Field & """ value=""" Value=Request.querystring(Field) Thestring=TheString + cstr(Value) & """>" & vbcrlf Response.Write TheString Next end if END function
'*//**//**//**//**//**//**//**//**//**//**//**//**//
'====================================================== ' Call the following function with: ' Call SaveAsCookie("TYPE1", "TYPE2") replacing TYPE1 and TYPE2 with: form, cookies or querystring. ' 'Lastly the function may be also be called as follows: 'Call SaveAsCookie("ALL", 0) calling the function in this way performs all three types. '====================================================== function SaveAsCookie (type1, type2) if lcase(type1)="form" or lcase(type2)="form" or lcase(type1)="all" then For Each Field In Request.Form Response.cookies(field)= Request.Form(Field) Next end if if lcase(type1)="cookies" or lcase(type2)="cookies" or lcase(type1)="all" then For Each Field In Request.cookies Response.cookies(field)= Request.cookies(Field) Next end if if lcase(type1)="querystring" or lcase(type2)="querystring" or lcase(type1)="all" then For Each Field In Request.Querystring Response.cookies(field)= Request.querystring(Field) Next end if END function '*//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//**//** ' TESTING THE CODE 'uncomment the code below to test the functions. 'Set up a form or something to call this page passing variables 'or manually pass querystring info when calling this page 'once the script is run, checking the resulting html source ' will reveal the result of the saveasformfields function 'try typing: formfunctions.asp?test1=testing&test2=numbers12345&test3=final-test 'into the browser. 'Uncomment below here ' 'call getvariables("all",0) 'call SaveAsFormFields("all",0) 'call SaveAsCookie("all",0) 'response.write vbcrlf & test1 & "<BR>" & test2 & "<BR>" & test3 & vbcrlf 'response.write "<BR><BR>Cookies<BR>-------<BR>" & vbcrlf 'for each item in request.cookies ' response.write(Request.cookies(item))&"<BR>" & vbcrlf 'next 'response.write "<B><BR>Click View...source to see where hidden form elements have been set.</b>" %> |
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More ASP Code Articles More By aspfree developerWorks - FREE Tools! | The IBM DB2 Deep Compression ROI tool is designed for DBA’s and IT management personnel to perform a clinical analysis of the cost savings gained from the Storage Optimization feature of DB2 9 for Linux, UNIX and Windows. The feature, also known as Deep Compression, compresses data that lies within a database by up to 80% at times. FREE! Go There Now!
| | | | David Barnes, Lead Evangelist for IBM Emerging Internet Technologies will discuss aspects of Web 2.0 that bring value to corporations, academia, and government. He'll also discuss IBM's vision around Web 2.0, including the importance of remixability and consumability. The discussion will culminate with examples of various IBM Software Group solutions you can use to get ahead of the Web 2.0 adoption curve. FREE! Go There Now!
| | | | As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
| | | | Visit IBM developerWorks to download the latest trial version of IBM Data Studio V1.1 at no cost. IBM Data Studio is a comprehensive data management solution that helps you effectively design, develop, deploy and manage your data, databases, and database applications throughout the data management life cycle utilizing a consistent and integrated user interface. Unlike other client-side data management solutions that focus on only one aspect of the application lifecycle or database administration, Data Studio complements the Rational Software Delivery platform, providing unparalleled flexibility for a heterogeneous data server environment across platforms. FREE! Go There Now!
| | | | This whitepaper provides areas to consider when evaluating any software configuration management solution. It addresses how the IBM solutions (Rational ClearCase and Rational ClearQuest) meet the needs and requirements of both project leaders and developers to provide successful Software Change and Configuration Management. FREE! Go There Now!
| | | | Get a free trial download of IBM Lotus Forms V3.0 (formerly Workplace Forms), which provides a zero-footprint eForms solution to help you automate and move forms-based business processes off the desktop and onto the Web. With Lotus Forms, you can extend applications beyond the firewall by creating a single electronic form document ready for use in both thick and Web 2.0 thin client format. FREE! Go There Now!
| | | | Join this Rational Talks to You teleconference, to hear how Enterprise Generation Language (EGL) eliminates the need for tedious and error-prone low level coding, so developers can focus on business requirements. EGL extends the Rational software development platform with a simplified programming language that enables developers who have little or no experience with Java, Web technologies or Service Oriented Architecture, to create enterprise-class applications and services quickly and easily. It also allows developers who may have little or no mainframe programming experience to quickly create traditional mainframe components. FREE! Go There Now!
| | | | Join the IBM Watchfire team for an informative discussion on techniques and best practices to proactively manage Web application security and how to effectively build application security testing into the software development lifecycle (SDLC). In this Software Delivery Platform webcast you will learn: How to better understand potential web application security vulnerabilities, best practices and how to effectively integrate application security testing into the software development lifecycle, the importance of detecting and removing software vulnerabilities during application development. FREE! Go There Now!
| | | | The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
| | | | User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges. FREE! Go There Now!
| | | | All FREE IBM® developerWorks Tools! | |